日期:2014-05-20  浏览次数:20862 次

java.lang.NoSuchMethodException: Action[/employee] does not contain specified me
Spring 配置文件
Java code
 <bean name="/employee" class="com.petclinic.struts.action.EmployeeAction">
        <property name="employeeService">
            <ref bean="employeeService" />
        </property>
    </bean>

Struts配置文件
Java code
<action parameter="method"  path="/employee" scope="request"
            type="org.springframework.web.struts.DelegatingActionProxy">
            <forward name="list" path="/pages/sysManage/employee.jsp" />
        </action>

Action
Java code
public ActionForward listEmployee(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response){
        List listEmployee=employeeService.findAllEmployee();
        System.out.println("listEmployee---->"+listEmployee);
        request.setAttribute("listEmployee", listEmployee);    
        return mapping.findForward("list");
    }


jsp页面部分
Java code
<html:link action="employee.do?method=listEmployee " target="mainFrame" styleClass="left-font03" onclick="list('5');">系统管理</html:link>

点击连接的时候就出异常
javax.servlet.ServletException: java.lang.NoSuchMethodException: Action[/employee] does not contain specified method (check logs)
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

希望有人帮忙解决下这个问题。

------解决方案--------------------
一般SSH框架整合步骤:
Java code

添加spring和hibernate有顺序问题
先加spring

修改web.xml

配置的是上下文参数
<context-param>
      <param-name>contextConfigLocation</param-name>名称是固定的,一定要记下来
      <param-value>classpath*:applicationContext*.xml</param-value>加载classes下面的所有以applicationContext开头的xml文件
</context-param>

加载上下文参数的监听器
<listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

两个过滤器,转码(CharacterEncodingFilter)和延迟加载(OpenSessionInViewFilter)


修改struts-config.xml
使用Spring的请求处理器
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"></controller>


修改applicationContext.xml,将Action交由spring管理
其中bean的一定要使用name属性进行声明,因为id不能接受/这个符号
name属性的值和struts-config.xml中action配置的path路径一致。

<bean name="/student"
    class="org.totong.struts.action.StudentAction">
    <property name="studentService" ref="studentService"></property>
</bean>

------解决方案--------------------
我估计是
你的JSP页面是存在于另一个目录下
当你处理完一个请求后跳转到当前页面
然后再请求action时路径变成了HTTP://localhost:8080/XXX/文件所在目录名/employee.do?method=listEmployee
而正确的路径HTTP://localhost:8080/XXX/文件所在目录名/employee.do?method=listEmployee