Two ways to change an HTML page to a JSP font: [Increase decrease] Type: Reprint time: 2013-08-13 There are two ways to change an HTML page to a JSP, the first is to modify the HTML file directly, and the other is to create a new JSP file. Below for the detailed introduction of the implementation of the specific, interested friends can refer to the general situation, the HTML page into a JSP has two methods, the first is to directly modify the HTML file, the other is a new JSP file. Here are a few of the two ways to do that.
Suppose we want to modify the testpage.html file to a testpage.jsp file. The contents of the original testpage.html file are:
Copy CodeThe code is 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 the HTML file
1. Add the following code directly at the top of the original testpage.html page:
Copy CodeThe code is as follows:
<%@ page language= "java" contenttype= "text/html; charset=gb18030 "
pageencoding= "GB18030"%>
2. Modify the file suffix name
Click the original testpage.html file, press F2, modify the suffix named Jsp,ok.
Fortunately, it should be done, but I have a little bit of a back, the following error interface:
However, once again the file suffix is changed to HTML, and can be displayed normally. Surf the internet for half a day and did not find a solution. Later inadvertently restarted the myeclipse,jsp page incredibly magically can show the normal, really let people without words, wasting so much time to solve a problem is not a problem.
The second type: Create a new JSP file
1. New file name is testpage.jsp file
2. Copy the contents of the original testpage.html file to the JSP file. Don't be silly. Even the contents of the JSP file header are covered, only the content of the HTML tag in the JSP file is OK.
3, delete the original testpage.html file can be.
Expand your knowledge
Copy CodeThe code is as follows:
<%@ page language= "java" contenttype= "text/html; charset=gb18030 "
pageencoding= "GB18030"%>
Explain the above code, page language= "Java" This everyone knows, do not explain. charset=gb18030 and pageencoding= "GB18030" are all set coded, what difference do they have? CHARSET=GB18030 refers to the encoding of the content that is output to the browser after this JSP finishes processing GB18030. Pageencoding= "GB18030" set is the JSP file itself encoding, we all know that the JSP file will be compiled into Java files (each JSP page in the work directory under Tomcat, will have the 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 some common encodings.
Iso-8859-1, this is the Western European language coding, using this encoding to encode Chinese is a problem. The default encoding for programs like Tomcat is ISO, which you want to interpret in Chinese, and how to set the encoding. This is also telling us the children of China, we have to work hard, add fuel, in the future to develop a good software, the default encoding is the Chinese encoding method. Do you want to use the foreigner? Want to use on their own to go to the code.
GB2312, GBK, GB18030 are our Chinese code (in fact, can also encode Japanese, Korean, etc.), gb2312-80 only 6,763 Chinese characters, GBK is gb2312-80 extension, is backward-compatible. GBK total income of 21,886 Chinese characters and graphic symbols. GB18030 currently has a encoded character of about 26,000. Can clearly see the coding range GB2312 < GBK < GB18030, however, I feel that we usually use those Chinese characters, with GBK code enough, you want to ah, even if there are 21886 outside the Chinese characters, I guess this ordinary small people do not know Ah, This is not the same as the effect of garbled, haha, joking.
UTF is an international code, that is to say, whether you are Chinese or Owen, there is a problem with this code. Perhaps some people will ask, in this case, all of our codes are set to UTF is not OK. Yes, no mistake, this is okay, but give us an example and you'll see. I usually go out, take things less, we have a pocket on the clothes can be. Occasionally do a thing need to bring some files or something, so we took a file package. Later, we are going to travel, you took a suitcase. So you think, things are less, with luggage can, take a file or something with the suitcase also no problem, travel also no problem, this luggage box versatility is really good, so you go out every day with a suitcase. Is it appropriate?
That's all you've written.
Two ways to change an HTML page to a JSP