我搭建一个小的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中:public 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路径错。
在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中:public 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路径错。
解决方案 »
- 各位侠客、都来看看啊。
- 这段代码有什么错误?
- 为什么我的Spring运行出错?
- 求助JSP 虚拟主机上做上传文件操作
- 请教各位jbuilder9+weblogic+oracle9i开发,需要怎样设置?????
- 尚学堂OA模块树展现问题,即(outlook.html转outlook.jsp出现的),高分悬赏谢谢
- jsp.error.badaction这是什么样的错误!?为了毕设就10分了!!!
- 在哪儿能下载JBulider 9或是JBulider X ?
- jspSmartUpload问题,紧急求助!!!
- 一个框架网页,如CSDN的论坛,左框架内用APPLET做的树型控件,点击后右框架内出现链接内容。
- java获取条形码扫描器扫描的值
- 菜鸟提问:Hibernate的HQL语句问题
<result name="all">/index.jsp</result>
</action>改成
<action name="FindEmpAll" method="FindEmpAll" class="Action.EmpAction">
<result name="all">/index.jsp</result>
</action>
试试
改成
<a href="test001!FindEmpAll.action">员工信息</a>
Struts2跳转,使用的是<action name="test001" class="Action.EmpAction">中的name的值来定位action的。
<package name="Test" extends="struts-default">
<action name="test001" class="Action.EmpAction">
<result name="all">/emp.jsp</result>
</action>
</package>我的emp.jsp:
<form action="" method="post" name="test001">
<table border="1" align="center" width="600">
<tr align="center">
<td colspan="5" align="center">
员工信息
</td>
</tr>
<tr align="center">
<td>
编号
</td>
<td>
姓名
</td>
<td>
性别
</td>
<td>
年龄
</td>
<td>
部门
</td> </tr>
<s:iterator value="emplist">
<tr>
<td>
<s:property value="id" />
</td>
<td>
<s:property value="name" />
</td>
<td>
<s:property value="sex" />
</td>
<td>
<s:property value="age" />
</td>
<td>
<s:property value="departmentId" />
</td> </tr>
</s:iterator>
</table>
</form>
Action.EmpAction包名怎么还大写?
<action name="test001" class="Action.EmpAction">
这个test001没有东西找它嘛
<a href="test001.action">试试
EmpAction是类的名字
EmpAction.java
System.out.println("在这里打印一些字符串,看能不能执行到这里,如果不能就是其他错误。而不是路径问题。");
emplist=emp.findAll();
return "all";
}
我在index.jsp中是根据你说的写的: <a href="test001!FindEmpAll.action">员工信息</a> 可以没有打印出来 404错误
// TODO Auto-generated method stub
return null;
}
你这里返回一个空对象啊。肯定是有问题的。
public class EmpAction { public List emplist; private EmpDAO emp; public EmpDAO getEmp() {
return emp;
} public void setEmp(EmpDAO emp) {
this.emp = emp;
}
public String FindEmpAll(){
System.out.println("123456");
emplist=emp.findAll();
return "all";
} }index.jsp中:
<a href="test001!FindEmpAll.action">员工信息</a> struts.xml中:
<package name="Test" extends="struts-default">
<action name="test001" class="Action.EmpAction">
<result name="all">/emp.jsp</result>
</action>
</package>运行后还是404错误
没见过这样的
我觉得因该不要packageName
直接就是
<a href="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下
Struts:
<package name="Test" extends="struts-default" namespace="/">
<action name="test001" class="Action.EmpAction" method="FindEmpAll">
<result name="success">/emp.jsp</result>
</action>
</package>Action:
public String FindEmpAll(){
emplist=emp.findAll();
return "success";
}JSP:
<a href="test001.action" >aaaaa</a>给搂住一点建议,在学习搭建struts工程是,用struts包下提供的example有一个blank工程,这样可以一次成功。因为我当初就老是搭建工程出错。有时会因为struts.xml文件有些不可见字符导致,其实没有错,但就是跑不出来。
你这个主要就是修改了index.jsp中的链接。结果还是报404错误404 - /Emp_Test/test001.action
Emp_Test是你的项目吧?
改下:
<a href="Test/test001.action" >aaaaa</a>
或者你的package name=""
引用 29 楼 monster1 的回复:
Emp_Test是你的项目吧?
改下:
<a href="Test/test001.action" >aaaaa</a>
或者你的package name=""
Emp_Test是项目名称<a href="Test/test001.action" >aaaaa</a>
这个方法之前试过了 404路径错误
struts.xml不是放在src下面么?
恩 修改过的:
web.xml:<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<filter>
<filter-name>action2-cleanup</filter-name>
<filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
</filter>
<filter-mapping>
<filter-name>action2-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
return emp;
} public void setEmp(EmpDAO emp) {
this.emp = emp;
}
public String FindEmpAll(){
System.out.println("123456");
emplist=emp.findAll();
return "all";
} }你的还是这样吗?
另外return和result保持一致哦
那在struts.xml中:
<action name="test001" class="Action.EmpAction">
<result name="all">/index.jsp</result>
</action>的class应该是class=“EmpAction” 吧;
试试。
改为<a href="/test001.action">在struts.xml中:
<action name="test001" class="Action.EmpAction">
<result name="all">/index.jsp</result>
</action>
改为
<package name="test" extends="struts-default" namespace="/">
<action name="test001" class="Action.EmpAction" method="findEmpall">
<result name="all">/emp.jsp</result>
</action>
</package>