Java 从一个jsp链接到另一个jsp文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22639896/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
From one jsp link to another jsp file
提问by sareeshmnair
In first jsp page i want a link forward to second jsp file. How can i do that.Both jsp files are in same folder.My folder structure as follows.
在第一个 jsp 页面中,我想要一个指向第二个 jsp 文件的链接。我该怎么做。两个jsp文件都在同一个文件夹中。我的文件夹结构如下。
WebContent
jsp
first.jsp
second.jsp
in my first.jsp
在我的第一个.jsp
<div>
<ul>
<li><a href="second.jsp" >click</a></li>
.
.
</ul>
</div>
but this doesn't work
但这不起作用
采纳答案by Paul Vargas
Maybe you need the context path of the Web application. Try this:
也许您需要 Web 应用程序的上下文路径。尝试这个:
<a href="${pageContext.request.contextPath}/jsp/second.jsp" >click</a>
回答by darijan
A common practice would be to create a servlet that would redirect to the second.jsp and then link the servet URL.
一种常见的做法是创建一个 servlet,该 servlet 将重定向到 second.jsp,然后链接服务器 URL。
回答by yelena
in your web.xml file map your jsp file:
在您的 web.xml 文件中映射您的 jsp 文件:
<servlet>
<servlet-name>second</servlet-name>
<jsp-file>second.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>second</servlet-name>
<url-pattern>/secondJsp</url-pattern>
</servlet-mapping>
The following will work then
以下将起作用
<li><a href="secondJsp" >click</a></li>