Two methods to change an html page to a jsp page

Source: Internet
Author: User

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. The two methods are described below.
Suppose we want to change the testpage.html file to the testPage. jsp file. The content of the original testpage.html file is:
Copy codeThe Code is as follows:
<! 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>

First: directly modify html files
1、directly Add the following code 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
Click the original testpage.html file and press F2 to change the suffix to jsp. OK.
If you are lucky, it should have been a success so far, but I have a little bit of back and the following error page appears:
 
However, after the file suffix is changed to html again, the file can be displayed normally. I did not find a solution after checking the Internet for half a day. Later, I accidentally restarted Myeclipse, And the jsp page was magically displayed. It was speechless and I wasted so much time solving a problem that was not a problem.

Type 2: Create a jsp file
1. Create a file named testPage. jsp.
2. Copy the content of the original testpage.html file to the jsp file. Don't be dumpily overwrite the content of the jsp file header. It's okay to only overwrite the html Tag content in the jsp file.
3. Delete the original testpage.html file.
Expand knowledge
Copy codeThe Code is as follows:
<% @ Page language = "java" contentType = "text/html; charset = GB18030"
PageEncoding = "GB18030" %>

For more information about the above Code, see page language = "java. Charset = GB18030 and pageEncoding = "GB18030" are both encoded. What are their differences? Charset = GB18030 indicates the encoding method of the content output to the browser after the jsp processing is GB18030. PageEncoding = "GB18030" sets the encoding of the jsp file. As we all know, the jsp file will be compiled into a java file (each jsp page is in the work directory under tomcat, corresponding java files and class files), and then proceed to the next step. The pageEncoding attribute sets the encoding method from the jsp file to the java file.
Next, let's take a look at several common encodings.

ISO-8859-1, This is the Western European language encoding, using this encoding to encode Chinese is a problem. For programs such as tomcat, the default encoding is iso. to interpret Chinese, you must set the encoding method. This is also telling our Chinese children that we have to work hard and work hard. In the future, we will develop an awesome software. The default encoding method is the Chinese encoding method. Do you want to use it as a foreigner? If you want to use it, transcode it yourself.
GB2312, GBK, GB18030 are my Chinese encoding (in fact, can also encode Japanese, Korean, etc.), GB2312-80 only receive 6763 Chinese characters, GBK is the extension of the GB2312-80, is backward compatible. GBK generates a total of 21886 Chinese characters and graphical symbols. GB18030 currently has an encoded string of about 26 thousand characters. We can clearly see that the encoding range is GB2312 <GBK <GB18030. However, I feel that the Chinese characters we usually use are fully GBK encoded, even if there are more than 21886 Chinese characters, it is estimated that we are not familiar with ordinary people. This is not the same as Garbled text. Haha, I am joking.
UTF is a universal international code, that is to say, whether you are a Chinese or Owen, there is a problem with this encoding. Some may ask, in this case, we can set all the codes to UTF. Yes, no error. This is acceptable, but you will understand it by giving an example. We usually go out and get less things. We can have a pocket on our clothes. Occasionally, we need to include some files or something, so we get a file package. Then, let's go on a tour. You have a suitcase. So you thought about it. There are fewer things. You can use a suitcase and take a file or something. There is no problem with travel. the versatility of this suitcase is really good, so you bring a suitcase when you go out every day. Is it appropriate?
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.