问题描述
- 报错!!!找不到action中welcome方法,求大神们赐教!
- HTTP Status 500 - The welcome() is not defined in action class com.opensymphony.xwork2.ActionSupport
type Exception reportmessage The welcome() is not defined in action class com.opensymphony.xwork2.ActionSupport
description The server encountered an internal error that prevented it from fulfilling this request.
exception
java.lang.IllegalArgumentException: The welcome() is not defined in action class com.opensymphony.xwork2.ActionSupport
com.opensymphony.xwork2.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:454)
com.opensymphony.xwork2.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:280)
com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:243)
org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)LoginAction类代码:package com.test.bean.web;import org.springframework.beans.factory.annotation.Autowired;import com.opensymphony.xwork2.ActionContext;import com.opensymphony.xwork2.ActionSupport;import com.opensymphony.xwork2.Preparable;import com.test.bean.entity.base.User;import com.test.bean.service.base.UserManager;/**系统登录@author Administrator**/@SuppressWarnings(""serial"")public class LoginAction extends ActionSupport implements Preparable{private String username; //登录用户名private String password; //登录密码@Autowiredprivate UserManager userManager; //操作员管理Sessionpublic String welcome(){return list();}public String list(){return SUCCESS;}public String login(){//获取用户信息User user=userManager.getUser(username password);if(user == null){addActionError(""用户名或密码不正确!"");return SUCCESS;}ActionContext actioncontext=ActionContext.getContext();actioncontext.getSession().put(""user"" user);return ""index"";}public String loginRedirect(){return ""index"";}public String logout(){//退出时清空session中的内容ActionContext actioncontext=ActionContext.getContext();actioncontext.getSession().put(""user"" null);return SUCCESS;}/**防止重复提示错误信息 */ public void prepare(){ // TODO Auto-generated method stub clearErrorsAndMessages(); } public void setUsername(String username){ this.username=username; } public void setPassword(String password){ this.password=password; } }
解决方案
LoginAction类代码:
package com.test.bean.web;
import org.springframework.beans.factory.annotation.Autowired;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.Preparable;
import com.test.bean.entity.base.User;
import com.test.bean.service.base.UserManager;
/**
- 系统登录
- @author Administrator
*
*/
@SuppressWarnings(""serial"")
public class LoginAction extends ActionSupport implements Preparable{private String username; //登录用户名
private String password; //登录密码@Autowired
private UserManager userManager; //操作员管理Session
public String welcome(){
return list();
}public String list(){
return SUCCESS;
}public String login(){
//获取用户信息
User user=userManager.getUser(username password);
if(user == null){
addActionError(""用户名或密码不正确!"");
return SUCCESS;}
ActionContext actioncontext=ActionContext.getContext();
actioncontext.getSession().put(""user"" user);
return ""index"";
}
public String loginRedirect(){
return ""index"";
}
public String logout(){
//退出时清空session中的内容
ActionContext actioncontext=ActionContext.getContext();
actioncontext.getSession().put(""user"" null);
return SUCCESS;
}/**
- 防止重复提示错误信息*/public void prepare(){// TODO Auto-generated method stubclearErrorsAndMessages();}public void setUsername(String username){this.username=username;}public void setPassword(String password){this.password=password;}}
解决方案二:
Struts版本包有问题,就是说你的jar包兼容问题,最好是所有的jar都是一个地方获取的,东拼西凑的jar包就可能出现你这个问题
解决方案三:
struts.xml里没配啊