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:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
First: directly modify HTML files
1、directly Add the following code at the top of the original testpage.html page:
<%@ 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
<%@ 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.