If you need to embed a file somewhere on the JSP page, you can use this command label. The command label is as follows:
<% @ Include file = "file name" %>
The command label is used to insert a static file at the location where the command appears on the JSP page. The inserted file must be accessible and usable, that is, the file must be in the same web service directory as the current JSP page. Static insertion means that the current JSP page and the inserted part are merged into a new JSP page, and then the JSP Engine translates the new JSP page into a JSP page file. For example, if a JSP page uses the include command to insert a JSP file, the inserted JSP page contains a page command that sets the page contentType attribute:
<% @ Page contentType = "text/html; charset = GB2312" %>
When the current JSP page has used the page command to set the attribute value of the contentType attribute, a syntax error occurs on the newly merged JSP page, if you translate the merged JSP page to a Java file, it will fail.
The following example is a static file named hello.txt on the jsppage. The content of this file is "I am a student, I major in computer science and technology.". The text file must be in the same web directory as the current JSP page.
<%@ page contentType="text/html;charset=GB2312"%><HTML><BODY bgcolor=cyan><FONT size=5><H3> <%@ include file="Hello.txt"%></H3></FONT></BODY>
The following is a static jsp file computer. JSP inserted in jsp.
The content of computer. jsp is as follows:
<FORM action = "" method = post name = form> <INPUT type = "text" name = "OK"> <INPUT TYPE = "submit" value = "haha" name = submit> </FORM> <% String a = request. getParameter ("OK"); if (a = null) {a = "1" ;}try {double number = Integer. parseInt (a); out. print ("<BR>" + Math. sqrt (number);} catch (NumberFormatException e) {out. print ("<BR>" + "enter a number") ;}%>
The following is a test. jsp test.
<% @ Page contentType = "text/html; charset = GB2312" %> <HTML> <BODY bgcolor = cyan> <FONT size = 5> <P> enter a positive number, click the button to find the square root of the number. <CENTER> <% @ include file = "computer. jsp" %> </CENTER> </FONT> </BODY>