Jsp include command label

Source: Internet
Author: User

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>



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.