![](/img/trans.png)
[英]How to change redirect.jsp to view my custom jsp page instead of index.jsp
[英]How to JSP display multiple page with one layout (Example index.jsp?page=about display about.jsp)
我是JSP的新手,我对JSP有问题
在PHP中我使用
$page=$_GET["page"]
对于显示一个布局的多个页面,这意味着我有索引,它显示布局,当我单击菜单时转到关于我们的索引url = index.jsp?page = about in PHP,当我在上面声明$ page时,我下一步
Switch($page){
case 1:about
include 'aboutus.php'
case 2:news
include 'news.php'
}
我该怎么做 ? JSP如何以相同的方式用PHP在1种布局中显示多个页面
使用jsp:include
。
<jsp:include page="/WEB-INF/${param.page}.jsp" />
并传递?page=news
或?page=about
等作为参数。 ${param.page}
打印request.getParameter("page")
。 通过将JSP文件放在/WEB-INF
文件夹中,可以防止直接访问JSP文件(通过在浏览器地址栏中输入URL)。
如今,您将Java Server Faces(JSF)的“模板”用于此方法。 使用JSP时,实际上并没有使用与PHP中相同的概念。 您最好使用MVC概念。 但是要回答您的问题,您可以使用包含标签http://java.sun.com/products/jsp/tags/11/syntaxref1112.html来实现,并使用JSTL对其进行控制: http://www.java2s。 com / Code / Java / JSTL / JSTLiftag.htm
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.