Specific example code for changing html page to jsp

零下一度
Release: 2017-04-25 14:23:25
Original
1480 people have browsed it

Generally, there are two ways to change an html page to jsp. The first is to directly modify the html file, and the other is to create a new jsp file. Let’s talk about these two methods in detail below.

Suppose we want to modify the testPage.html file to the testPage.jsp file. The content of the original testPage.html file is:

[html]<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body>  </body> </html> 
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Insert title here</title></head><body>
</body></html>
Copy after login

The first method: modify the html file directly

1. Add the following code directly to the top of the original testPage.html page:

[html]<%@ page language="java" contentType="text/html; charset=GB18030"     pageEncoding="GB18030"%> 
<%@ page language="java" contentType="text/html; charset=GB18030"    pageEncoding="GB18030"%>
Copy after login

2. Modify the file suffix

Click on the original testPage.html file, press F2, change the suffix to jsp, and OK.

If you are lucky, you should be done by now, but I am a little confused and the following error interface appears:

But after changing the file suffix to html again, it can be displayed normally again . I searched online for a long time and couldn't find a solution. Later, I accidentally restarted Myeclipse, and the jsp page miraculously displayed normally. I was really speechless, wasting so much time to solve a problem that was not a problem.

Second type: Create a new jsp file

1. Create a new file named testPage.jsp file

2. Copy the contents of the original testPage.html file to the jsp file . Don't be so foolish as to cover the content of the jsp file header. Just cover the content of the html tag in the jsp file.

3. Delete the original testPage.html file.

Expand knowledge

[html]<%@ page language="java" contentType="text/html; charset=GB18030"     pageEncoding="GB18030"%> 
<%@ page language="java" contentType="text/html; charset=GB18030"
Copy after login

pageEncoding="GB18030"%>Explain the above code, page language="java" everyone understands this and does not explain it. charset=GB18030 and pageEncoding="GB18030" both set the encoding. What is the difference between them? charset=GB18030 means that the encoding method of the content output to the browser after this jsp is processed is GB18030. pageEncoding="GB18030" sets the encoding of the jsp file itself. As we all know, jsp files will be compiled into java files (each jsp page will have corresponding java files and class files in the work directory under tomcat) ) before continuing to the next step. The pageEncoding attribute here is to set the encoding method from jsp file to java file.

Let’s take a brief look at some common encodings.

ISO-8859-1, this is the encoding of Western European languages. Using this encoding to encode Chinese will cause problems. The default encoding of programs such as tomcat is iso. If you want it to interpret Chinese, you must set the encoding method. This also tells us Chinese sons and daughters that we have to work hard and work hard to develop an awesome software in the future. The default encoding is the Chinese encoding method. Do you want to use it as a foreigner? If you want to use it, just transcode it yourself.

GB2312, GBK, and GB18030 are all Chinese encodings (in fact, they can also encode Japanese, Korean, etc.). GB2312-80 only accepts 6763 Chinese characters. GBK is an extension of GB2312-80 and is backward compatible. . GBK contains a total of 21,886 Chinese characters and graphic symbols. GB18030 currently has about 26,000 encoded characters. It can be clearly seen that the encoding range is GB2312 < GBK < GB18030. However, I feel that GBK encoding is enough for the Chinese characters we usually use. Think about it, even if Chinese characters other than 21886 appear, I guess we Ordinary people don’t know this. Isn’t this the same effect as garbled characters? Haha, just kidding.

UTF is an internationally accepted encoding, which means that no matter you are Chinese or Owen, there will be no problem using this encoding. Some people may ask, in this case, can't we just set all encodings to UTF? Yes, it’s not wrong, this is possible, but I’ll give you an example and you’ll understand. When we usually go out, we carry relatively few things, so just having a pocket on our clothes is enough. Occasionally, we need to bring some documents or something to do something, so we took a document bag. Later, we were going on a trip and you brought a suitcase. So you thought, if you have few things, you can use a suitcase. It’s no problem to use a suitcase to carry documents or something, and it’s no problem to travel. The versatility of this suitcase is really good, so you take a suitcase with you every day when you go out. . Does it fit?

Just write this much.

The above is the detailed content of Specific example code for changing html page to jsp. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!