Two ways to change an HTML page into a JSP _jsp programming

Source: Internet
Author: User
Tags tomcat
In general, there are two ways to change the HTML page to JSP, the first is to modify the HTML file directly, the other is to create a new JSP file. Here are two ways to be specific.
Suppose we want to modify the testpage.html file to a testpage.jsp file. The original testpage.html file contents are:
Copy Code code as follows:

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>insert title here</title>
<body>
</body>

First: Directly modify HTML files
1. Add the following code directly to the top of the original testpage.html page:
Copy Code code as follows:

<%@ page language= "java" contenttype= "text/html; charset=gb18030 "
pageencoding= "GB18030"%>

2. modify file suffix name
Click the original testpage.html file, press F2, modify the suffix named Jsp,ok can be.
With luck, this should be the end, but I am a little bit back, the following error interface appears:

But once again the file suffix is changed to HTML, and can be displayed normally. Online search for a long time also did not find a solution. Then inadvertently restarted the myeclipse,jsp page incredibly magical to show the normal, really let people have no language, waste so much time to solve a problem is not an issue.

Second: Create a new JSP file
1, new file name is testpage.jsp file
2. Copy the contents of the original testpage.html file into the JSP file. Don't be silly. Even the contents of the header of the JSP file are covered, only the content of the HTML tags in the JSP file is OK.
3, delete the original testpage.html file can be.
Expand your knowledge
Copy Code code as follows:

<%@ page language= "java" contenttype= "text/html; charset=gb18030 "
pageencoding= "GB18030"%>

Explain the above code, page language= "Java" This everyone understand, do not explain. charset=gb18030 and pageencoding= "GB18030" are set to encode, what is the difference between them? charset=gb18030 refers to the content of the output to the browser after this JSP is processed to encode the GB18030. Pageencoding= "GB18030" set is the code of the JSP file itself, as we all know, JSP files will be compiled into a Java file (each JSP page in the work directory under Tomcat, there will be corresponding Java files and class files), Then proceed to the next step. The Pageencoding property here is to set the encoding from the JSP file to the Java file.
Here's a quick look at a few common encodings.

Iso-8859-1, this is the encoding of Western European languages, it can be problematic to encode Chinese with this encoding. The default encoding for programs like Tomcat is ISO, and you want it to interpret Chinese, and you have to set the encoding. This is also to tell us Chinese children, I have to work hard, add fuel, the future development of a good software, the default encoding is the Chinese encoding method. Foreigner, do you want to use it? I want to use it to turn the code.
GB2312, GBK, GB18030 are all my Chinese coding (in fact, can also encode Japanese, Korean, etc.), gb2312-80 only 6,763 Chinese characters, GBK is the extension of gb2312-80, is backward-compatible. GBK has a total income of 21,886 Chinese characters and graphic symbols. GB18030 currently has encoded characters of about 26,000. Can obviously see the coding range GB2312 < GBK < GB18030, however, I feel, we usually use those Chinese characters, with GBK coding enough, you want to ah, even if the emergence of these 21886 of Chinese characters, I guess this ordinary people do not know Ah, This is not the same as the effect of garbled, haha, joking.
UTF is an international code, which means that no matter whether you are Chinese or Owen, there is a problem with this code. Maybe someone will ask, in this case, all of our coding is set to UTF not on the line. Yes, there is no mistake, this is OK, but for you to give an example you will understand. We usually go out, take things less, we have a pocket on the clothes can be. Occasionally do something need to bring some documents or something, so we took a file bag. Later, we are going to travel, you took a suitcase. So you think, things less, with a suitcase can be, take a file or something with a suitcase is no problem, travel is no problem, the general versatility of this suitcase is very good, so you go out every day with a suitcase. Does it fit?
Just write so much.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.