java.lang.NoSuchMethodException: Action[/employee] does not contain specified me

qin09872006 2010-03-13 11:50:50
Spring 配置文件
 <bean name="/employee" class="com.petclinic.struts.action.EmployeeAction">
<property name="employeeService">
<ref bean="employeeService" />
</property>
</bean>

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

Action
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页面部分

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

希望有人帮忙解决下这个问题。
...全文
679 26 打赏 收藏 转发到动态 举报
写回复
用AI写文章
26 条回复
切换为时间正序
请发表友善的回复…
发表回复
kiven032190 2011-11-02
  • 打赏
  • 举报
回复
哎...本人页刚学框架,路径问题确实恼火啊!总是出问题
loveskyliu 2011-06-15
  • 打赏
  • 举报
回复
还是来不起 我的eclipse里运行可以跑的起 打成war包放在 tomcat里就不行了 求解
qin09872006 2010-03-18
  • 打赏
  • 举报
回复
原因是我没有在action前面加项目名。我的struts配置中有多个action,/add_employee、/edit_employee 都是来自EmployeeAction继承自diapatchAction,
全部交由Spring控制,这些都必须加项目名才能正常跳转。
如果是直接用/employee下的跳转就不需要加项目名。
这个路径问题还真有点搞不明白。
Arthur0088 2010-03-17
  • 打赏
  • 举报
回复
路径问题啊,学习。。。。。
qin09872006 2010-03-17
  • 打赏
  • 举报
回复
终于找到了解决办法。原来是自己的页面路径不对。我在.do前添加了${path}就能正常跳转了。
岁月之梦 2010-03-17
  • 打赏
  • 举报
回复
你结贴率高的话 我还帮你看看!
Z-one-Z 2010-03-17
  • 打赏
  • 举报
回复
我估计是
你的JSP页面是存在于另一个目录下
当你处理完一个请求后跳转到当前页面
然后再请求action时路径变成了HTTP://localhost:8080/XXX/文件所在目录名/employee.do?method=listEmployee
而正确的路径HTTP://localhost:8080/XXX/文件所在目录名/employee.do?method=listEmployee
无红色部分
qin09872006 2010-03-16
  • 打赏
  • 举报
回复
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>

<filter>
<filter-name>Set Character Encoding</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
qin09872006 2010-03-16
  • 打赏
  • 举报
回复
今晚我回去看下我的源代码,我记得我好像写了监听器的。
灵犀Sword 2010-03-15
  • 打赏
  • 举报
回复
一般SSH框架整合步骤:

添加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>

灵犀Sword 2010-03-15
  • 打赏
  • 举报
回复
还有监听
灵犀Sword 2010-03-15
  • 打赏
  • 举报
回复
把web.xml贴出来 应该没写代理或者 过滤器
qin09872006 2010-03-14
  • 打赏
  • 举报
回复
现在根本就进入不了Action中。
谁能给我个比较明确的struts Spring hibernate 框架的各种配置步骤。
以及使用该框架应该注意些什么。
qin09872006 2010-03-14
  • 打赏
  • 举报
回复
我的Action是继承的DispatcherAction,当中也有相应的的方法listEmployee。
Struts配置文件中没有path相同的。
action值后面method不就是Sturts配置文件中parameter的值吗?就是parameter=method
页面上使用的提交方式,action是应该没有写错的啊。但就是找不到原因。
duiduiaa 2010-03-14
  • 打赏
  • 举报
回复
java.lang.NoSuchMethodException 这个异常是指你的action里面没有这个方法,说明已经找到了action 但是没有找到方法,所以有2个情况,一个是你提交到的不是这个action ,查查配置文件,有没有一样的path


第2种情况,你的action里面没有这个方法
wzju64676266 2010-03-14
  • 打赏
  • 举报
回复
actionform自动封装功能无非就是使用反射获取request里面的参数值,
要往action里面传什么值?method吗?
真真真真真真 2010-03-14
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 wzju64676266 的回复:]
引用 8 楼 kecy_niuniu 的回复:
Java code

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


链接中参数action值后面method是参……
[/Quote]
是可以不要,但是他要往action里面传值还是需要actionform封装吧
wzju64676266 2010-03-14
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 kecy_niuniu 的回复:]
Java code

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


链接中参数action值后面method是参数名,listEmployee是你要传的参数,st……
[/Quote]

不一定要有actionform啊老大,这个是可选的,问题不在这里
qin09872006 2010-03-13
  • 打赏
  • 举报
回复
public class EmployeeAction extends BaseAction

是写在这个类里面的 那个BaseAction是继承DispatcherAction的。

public class BaseAction extends DispatchAction {
private static ApplicationContext ctx = null;
public Object getBean(String name) {
if (ctx == null) {
ctx = WebApplicationContextUtils.getRequiredWebApplicationContext(
servlet.getServletContext());
}
return ctx.getBean(name);
}
}
wzju64676266 2010-03-13
  • 打赏
  • 举报
回复
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");
}

这段代码是
com.petclinic.struts.action.EmployeeAction这个类里面的吗?不要看清楚有没有哪里写错了,照理来说你的代码没有问题
加载更多回复(6)

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧