SSH框架练习 Action跳转我搭建一个小的SSH项目。在Index.jsp中:body a hrefEmpAction!FindEmpAll.acti
SSH框架练习 Action跳转
我搭建一个小的SSH项目。
在Index.jsp中:
<body> <a href="EmpAction!FindEmpAll.action">员工信息</a> </body>
在struts.xml中:
<action name="test001" class="Action.EmpAction">
<result name="all">/index.jsp</result>
</action>
在Action中:
Java codepublic class EmpAction { public List emplist; EmpDAO emp=EmpDAO(); public String FindEmpAll(){ emplist=emp.findAll(); return "all"; } private EmpDAO EmpDAO() { // TODO Auto-generated method stub return null; } }
项目启动后直接就报404路径错。
[解决办法]<action name="test001" class="Action.EmpAction">
<result name="all">/index.jsp</result>
</action>
改成
<action name="FindEmpAll" method="FindEmpAll" class="Action.EmpAction">
<result name="all">/index.jsp</result>
</action>
试试
[解决办法]<a href="EmpAction!FindEmpAll.action">员工信息</a>
改成
<a href="test001!FindEmpAll.action">员工信息</a>
Struts2跳转,使用的是<action name="test001" class="Action.EmpAction">中的name的值来定位action的。
[解决办法]EmpAction!FindEmpAll.action什么意思在?
Action.EmpAction包名怎么还大写?
<action name="test001" class="Action.EmpAction">
这个test001没有东西找它嘛
<a href="test001.action">试试
[解决办法] public String FindEmpAll(){
System.out.println("在这里打印一些字符串,看能不能执行到这里,如果不能就是其他错误。而不是路径问题。");
emplist=emp.findAll();
return "all";
}
[解决办法]另外,EmpAction 为是在src/Action包下面吗?
[解决办法]0.0 去百度看struts 我晕死!!!
[解决办法]<a href="packageName/actionName!方法名.action" ></a>
[解决办法]终于知道你的问题了。
private EmpDAO EmpDAO() {
// TODO Auto-generated method stub
return null;
}
你这里返回一个空对象啊。肯定是有问题的。
[解决办法]<a href="packageName/actionName!方法名.action" ></a>
没见过这样的
[解决办法]试试吧
Struts:
<package name="Test" extends="struts-default" namespace="/">
<action name="test001" class="Action.EmpAction" method="FindEmpAll">
<result name="all">/emp.jsp</result>
</action>
</package>
JSP:
<a href="Test/test001.action" ></a>
另外注意下emp.jsp应该直接放到WebRoot下