2 bjl710640289 bjl710640289 于 2014.12.12 11:11 提问

报错!!!找不到action中welcome方法,求大神们赐教!

HTTP Status 500 - The welcome() is not defined in action class com.opensymphony.xwork2.ActionSupport


type Exception report

message 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; //登录密码

@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 stub clearErrorsAndMessages(); } public void setUsername(String username){ this.username=username; } public void setPassword(String password){ this.password=password; } }

3个回答

bjl710640289
bjl710640289   2014.12.12 11:16

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 stub clearErrorsAndMessages(); } public void setUsername(String username){ this.username=username; } public void setPassword(String password){ this.password=password; } }
wsm201005030226
wsm201005030226   2014.12.12 12:41

Struts版本包有问题,就是说你的jar包兼容问题,最好是所有的jar都是一个地方获取的,东拼西凑的jar包就可能出现你这个问题

wsm201005030226
wsm201005030226 回复bjl710640289: 这种情况下,java应该是没什么问题的,你再检查一下你web.xml中所引入的文件名是否正确,主要检查<**-class>aaaa</**-class>的值,一般情况下这里出错比较多,你再**.java文件中首行这样写"import aaaa;"看是否报错
接近 3 年之前 回复
bjl710640289
bjl710640289 谢谢你的回答!但是包的版本没问题,原来位置都在不同的文件夹,我这回都放一起了还是报错
接近 3 年之前 回复
sunbo624
sunbo624   2014.12.12 16:42

struts.xml里没配啊

Csdn user default icon
上传中...
上传图片
插入图片