ThinkChat2.0新版上线,更智能更精彩,支持会话、画图、阅读、搜索等,送10W Token,即刻开启你的AI之旅 广告
# JSP `include`动作标签 > 原文: [https://beginnersbook.com/2013/11/jsp-include-action-tag/](https://beginnersbook.com/2013/11/jsp-include-action-tag/) `Include`动作标签用于将另一个资源包含到当前 JSP 页面。包含的资源可以是 HTML,JSP 页面或 Servlet 中的静态页面。我们还可以将参数及其值传递给我们所包含的资源。下面我分享了两个`<jsp:include>`的示例,其中一个包含一个页面而没有传递任何参数,在第二个示例中,我们将几个参数传递给正在包含的页面。 **语法:** 1)包含参数。 ```html <jsp:include page="Relative_URL_Of_Page"> <jsp:param ... /> <jsp:param ... /> <jsp:param ... /> ... <jsp:param ... /> </jsp:include> ``` 2)包含另一个没有共享参数的资源。 ```html <jsp:include page="Relative_URL_of_Page" /> ``` 如果页面位于当前 JSP 所在的同一目录中,`Relative_URL_of_Page`将是页面名称。 ### 示例 1:没有参数的`<jsp:include>` 在这个例子中,我们将使用没有参数的`<jsp:include>`动作标签。因此,页面将包含在当前 JSP 页面中: `index.jsp` ```html <html> <head> <title>JSP Include example</title> </head> <body> <b>index.jsp Page</b><br> <jsp:include page="Page2.jsp" /> </body> </html> ``` `Page2.jsp` ```html <b>Page2.jsp</b><br> <i> This is the content of Page2.jsp page</i> ``` **输出:** `Page2.jsp`的内容已附加在`index.jsp`中。 ![IncludeAction-output](https://img.kancloud.cn/0b/51/0b5129662c3cba0f9fe62f37a4633c04_503x263.jpg) ### 示例 2:使用`<jsp:include>`以及`<jsp:param>` `index.jsp` 我正在使用`<jsp:include>`和`<jsp:param>`动作,将参数传递给我们将要包含的页面。 ```html <html> <head> <title>JSP Include example with parameters</title> </head> <body> <h2>This is index.jsp Page</h2> <jsp:include page="display.jsp"> <jsp:param name="userid" value="Chaitanya" /> <jsp:param name="password" value="Chaitanya" /> <jsp:param name="name" value="Chaitanya Pratap Singh" /> <jsp:param name="age" value="27" /> </jsp:include> </body> </html> ``` `display.jsp` ```html <html> <head> <title>Display Page</title> </head> <body> <h2>Hello this is a display.jsp Page</h2> UserID: <%=request.getParameter("userid") %><br> Password is: <%=request.getParameter("password") %><br> User Name: <%=request.getParameter("name") %><br> Age: <%=request.getParameter("age") %> </body> </html> ``` **输出:** 正如您所看到的,`display.jsp`的内容已包含在`index.jsp`中。此外,我们传递的参数正在包含的页面中正确显示。 ![include-action-with-parameters-output](https://img.kancloud.cn/bd/c8/bdc8665a8e1a4a4a2a78b09e77009c59_503x263.jpg) 如果您对该主题有任何疑问和疑问,请告诉我们。我们很乐意帮助您!!