刚练struts,想简单地通过链接格式<a href>来访问web-inf自定义文件夹里的jsp。我的思路是写个action来间接访问。但调了一天了,真不知自己哪里错了,总是访问不了。麻烦大家帮忙看看。相关代码如下:
struts-config.xml
......
<action
attribute="exerciseListForm"
name="exerciseListForm"
path="/exerciseList"
scope="request"
type="com.ustc.struts.action.ExerciseListAction" >
<forward name="ch2List" path="/WEB-INF/jsp/ch2/exerciseList.jsp"></forward>
</action>welcome.jsp
......
<a href="exerciseList.do?actionId='ch2List'">ch2</a>ExerciseListAction.java
......
public class ExerciseListAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) { ExerciseListForm exerciseListForm = (ExerciseListForm) form;// TODO Auto-generated method stub
return mapping.findForward(exerciseListForm.getActionId());
}
}另外,ExerciseListForm.java里的变量就是传递的变量actionId但总是报错如下:
HTTP Status 404 - /Project02/WEB-INF/jsp/exerciseList.do
--------------------------------------------------------------------------------
type Status report
message /Project02/WEB-INF/jsp/exerciseList.do
description The requested resource (/Project02/WEB-INF/jsp/exerciseList.do) is not available.我认真分析了下,觉得原因是<a href>里写的action根本就没有提交给ActionServlet,而是直接简单的将<a href>所在的页面的路径(/Project02/WEB-INF/jsp/)加上我在超链接里写的内容(exerciseList.do?actionId='ch2List')后,就直接在浏览器里访问了(浏览器里显示的地址也是:http://localhost:8080/Project02/WEB-INF/jsp/exerciseList.do?actionId=ch2List)诚心请教大侠该怎么做才能成功的实现welcome.jsp页面里用超链接跳转到/WEB-INF/jsp/ch2/exerciseList.jsp
struts-config.xml
......
<action
attribute="exerciseListForm"
name="exerciseListForm"
path="/exerciseList"
scope="request"
type="com.ustc.struts.action.ExerciseListAction" >
<forward name="ch2List" path="/WEB-INF/jsp/ch2/exerciseList.jsp"></forward>
</action>welcome.jsp
......
<a href="exerciseList.do?actionId='ch2List'">ch2</a>ExerciseListAction.java
......
public class ExerciseListAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) { ExerciseListForm exerciseListForm = (ExerciseListForm) form;// TODO Auto-generated method stub
return mapping.findForward(exerciseListForm.getActionId());
}
}另外,ExerciseListForm.java里的变量就是传递的变量actionId但总是报错如下:
HTTP Status 404 - /Project02/WEB-INF/jsp/exerciseList.do
--------------------------------------------------------------------------------
type Status report
message /Project02/WEB-INF/jsp/exerciseList.do
description The requested resource (/Project02/WEB-INF/jsp/exerciseList.do) is not available.我认真分析了下,觉得原因是<a href>里写的action根本就没有提交给ActionServlet,而是直接简单的将<a href>所在的页面的路径(/Project02/WEB-INF/jsp/)加上我在超链接里写的内容(exerciseList.do?actionId='ch2List')后,就直接在浏览器里访问了(浏览器里显示的地址也是:http://localhost:8080/Project02/WEB-INF/jsp/exerciseList.do?actionId=ch2List)诚心请教大侠该怎么做才能成功的实现welcome.jsp页面里用超链接跳转到/WEB-INF/jsp/ch2/exerciseList.jsp
解决方案 »
- Spring+JPA+Hibernate诡异问题
- 求助hibernate自动插入中间表数据
- java 操作云盘 www.box.com
- cas单点登录和ad整合问题
- 求助,比较字符串后4位的HQL和SQL语句!
- 哪有java.io.BufferedReader的源码
- String型 转 Int型的问题
- com/sun/enterpris这个包在那个jar文件中
- 各位高手大哥.我是新注册的.没什么分分..555.请各位大哥帮忙看一下吧
- eclipse+myeclipse+jboss 开发ejb 如何配置啊 急
- 有关request.getParameterValues的问题
- 求助 jspsmartupload 出现Files' name is invalid or does not exist
这个好像不对的。
你可以先把它换成一个绝对URL。
如:http://localhost:8080/yourApp/exerciseList.do?actionId=ch2List
这样来试试。
如果你直接这样写:
href="exerciseList.do?actionId='ch2List'
这个路径,应该是将你当前jsp所在路径加在前面的url。
比如你当前jsp是:/Project02/WEB-INF/jsp/test.jsp
那么超级链接的完整url就是:
http://localhost:8080/Project02/WEB-INF/jsp/exerciseList.do?actionId='ch2List'
我的当前页面welcome.jsp的路径是/Project02/WEB-INF/jsp/welcome.jsp;
超链接想访问的jsp的路径是/Project02/WEB-INF/jsp/ch2/exerciseList.jsp。
<a href="/exerciseList.do?actionId=ch2List">ch2</a>
<a href="http://localhost:8080/Project02/exerciseList.do?actionId=ch2List">ch2</a>这两个应该是等效的。
第二个如果还不行的话,你就应该检查你的web.xml和strut的配置了。
你这个东东不是个字符串吗?如果是个变量的话应该用EL表达式括起来才对呀...
web.xml
....
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
....
</servlet> <servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<a href="http://localhost:8080/Project02/exerciseList.do?actionId=ch2List">ch2</a>
这个不行么?
把浏览器的缓存清理以后再试。
这样写我不确定是不是正确了。
但我认为没有问题的。
对于一个web app来说,它不会跳转到另外一个web app的,浏览器也不可能知道你想跳转到哪个web app。
所以说。/表示当前web app的根,也就是:http://localhost:8080/yourApp。
而/exerciseList.do就应该表示:http://localhost:8080/yourApp/exerciseList.do了。
HTTP Status 404 - /Project02/WEB-INF/jsp/exerciseList.do
--------------------------------------------------------------------------------
你的action访问路径是:path="/exerciseList"
我的一个计数器问题(关于相对路径和绝对路径的问题) http://www.phome.asia/forum/thread/6072.html