我搭建一个小的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路径错。

解决方案 »

  1.   

    <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>
    试试
      

  2.   

    <a href="EmpAction!FindEmpAll.action">员工信息</a>
    改成
    <a href="test001!FindEmpAll.action">员工信息</a>
    Struts2跳转,使用的是<action name="test001" class="Action.EmpAction">中的name的值来定位action的。
      

  3.   

    我在Struts.xml中有做了一点修改:
    <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>
      

  4.   

    EmpAction!FindEmpAll.action什么意思在?
    Action.EmpAction包名怎么还大写?
    <action name="test001" class="Action.EmpAction">
    这个test001没有东西找它嘛
    <a href="test001.action">试试
      

  5.   


    EmpAction是类的名字
    EmpAction.java
      

  6.   

     public String FindEmpAll(){
            System.out.println("在这里打印一些字符串,看能不能执行到这里,如果不能就是其他错误。而不是路径问题。");
            emplist=emp.findAll();
            return "all";
        }
      

  7.   

    我是想通过Index.jsp画面来执行一下FindEmpAll()方法,同时在emp.jsp画面中将数据显示出来,很简单的功能啊
      

  8.   

    另外,EmpAction 为是在src/Action包下面吗?
      

  9.   

    0.0 去百度看struts  我晕死!!!
      

  10.   


    我在index.jsp中是根据你说的写的: <a href="test001!FindEmpAll.action">员工信息</a> 可以没有打印出来 404错误
      

  11.   

    <a href="packageName/actionName!方法名.action" ></a>
      

  12.   

    终于知道你的问题了。 private EmpDAO EmpDAO() {
            // TODO Auto-generated method stub
            return null;
        }
    你这里返回一个空对象啊。肯定是有问题的。
      

  13.   

    我改成这样:
    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错误
      

  14.   

    <a href="packageName/actionName!方法名.action" ></a>
    没见过这样的
      

  15.   


    我觉得因该不要packageName
    直接就是
    <a href="actionName!方法名.action" ></a>
      

  16.   

    试试吧
    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下
      

  17.   

    具体情况具体对待,即使你现在不用以后也会用到的,path好像是用/分割,!做什么用啊?
      

  18.   

    搂主试试
    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文件有些不可见字符导致,其实没有错,但就是跑不出来。
      

  19.   


    你这个主要就是修改了index.jsp中的链接。结果还是报404错误404 - /Emp_Test/test001.action
      

  20.   

    The requested resource (/Emp_Test/test001.action) is not available.
      

  21.   


    Emp_Test是你的项目吧?
    改下:
    <a href="Test/test001.action" >aaaaa</a>
    或者你的package  name=""
      

  22.   

    哦,看错了,不会是你的struts.xml位置放的不对吧?
      

  23.   

    [Quote=引用 32 楼 xinyu1017 的回复:]
    引用 29 楼 monster1 的回复:

    Emp_Test是你的项目吧?
    改下:
    <a href="Test/test001.action" >aaaaa</a>
    或者你的package name=""
    Emp_Test是项目名称<a href="Test/test001.action" >aaaaa</a>
    这个方法之前试过了 404路径错误
      

  24.   


    struts.xml不是放在src下面么?
      

  25.   

    不知道你有没有修改web.xml呢?
      

  26.   

    这是路径:http://blog.csdn.net/zhengjf123/article/details/6801240
      

  27.   


    恩 修改过的:
    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>
      

  28.   

    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";
        }    }你的还是这样吗?
      

  29.   

    我刚简单搭建了下,是的话,改下 private EmpDAO emp=new EmpDAO();
    另外return和result保持一致哦
      

  30.   

    楼主的Action类貌似没有package Action;这句吧,
    那在struts.xml中:
    <action name="test001" class="Action.EmpAction">
    <result name="all">/index.jsp</result>
    </action>的class应该是class=“EmpAction” 吧;
    试试。
      

  31.   

    去看下Struts2权威指南,网上可以下的,里面说的非常清晰,一步一步的
      

  32.   

    Struts.xml中package 里 的namespace="/" 还是很重要的额 
      

  33.   

    <a href="EmpAction!FindEmpAll.action">员工信息</a> 
    改为<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>