struts2注解求助

beiguofengguang 2010-03-02 07:38:32
我定义了一个接收vchangpwd.jsp请求的action,代码如下:
package com.newland.gxbc.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;

import com.newland.gxbc.domain.ChangePwdFacade;
import com.opensymphony.xwork2.ActionSupport;

/**
* 修改操作员登录密码
*
* @author xianjiang
*
*/

@Scope("request")
@Namespace("/login")
@ParentPackage("default")
@InterceptorRefs(@InterceptorRef("basicStack"))
@SuppressWarnings("unchecked")

public class ChangePwdAction extends ActionSupport {

/**
*
*/
private static final long serialVersionUID = 5668033529924546285L;

private static final Log logger = LogFactory.getLog(ChangePwdAction.class);

private String oldPwd;

private String newPwd;

private String newPwd1;

static {
System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<11111");
}

@Autowired
private ChangePwdFacade changePwdFacade;

@Action(value="changepwd", results = {
@Result(name = "success", location = "/login/login.jsp", type = "redirect"),
@Result(name = "none", location = "/login/login.jsp", type="redirect") })


public String changeOperPwd(String oldPwd, String newPwd, String newPwd1){
System.out.println("a123");
HttpServletRequest request = ServletActionContext.getRequest();
HttpSession session = request.getSession();
String userId = (String) session.getAttribute("userId");

int ret = changePwdFacade.changePwd(userId, oldPwd, newPwd);

if (ret == 0) {
return SUCCESS;
} else {
return NONE;
}

}

public String getOldPwd() {
return oldPwd;
}

public void setOldPwd(String oldPwd) {
this.oldPwd = oldPwd;
}

public String getNewPwd() {
return newPwd;
}

public void setNewPwd(String newPwd) {
this.newPwd = newPwd;
}

public String getNewPwd1() {
return newPwd1;
}

public void setNewPwd1(String newPwd1) {
this.newPwd1 = newPwd1;
}

}

现在的问题是请求提交后程序未能进入changeOperPwd函数,请有经验的朋友给指点下,是不是哪里还需要什么配置?
...全文
623 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
yanick 2010-08-02
  • 打赏
  • 举报
回复
用注解 struts.xml如何配置?
xzl172259412 2010-07-22
  • 打赏
  • 举报
回复
呵呵 ,我最近也在看这个东东,希望大家有什么心得可以分享下子呀
beiguofengguang 2010-03-04
  • 打赏
  • 举报
回复
搞定了,是因为在定义那个事件的时候加了参数,把参数去掉就会自动执行的。谢谢大家的热心帮助
weixingwx911 2010-03-03
  • 打赏
  • 举报
回复
struts2.0默认调用execute() 方法,我原来用自己的方法的时候都是在页面上定义好的。你这种注解个人认为是配置文件没有写正确。
web.xml------
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
struts2.xml----------
<package name="action" namespace="/" extends="struts-default">
<action name="login" class="action.LoginAction">
<result name="success">/welcome.jsp</result>
<result name="error">/error.jsp</result>
<result name="input">/login.jsp</result>
</action>
</package>
Epiphone 2010-03-03
  • 打赏
  • 举报
回复
在使用这些注解的时候,还需要进行额外的一些配置。在web.xml的filter配置中,需要指定哪些package是使用了注解的。配置如下所示,其中参数名必须为“actionPackages”,参数的值就是package的名称列表。
<filter>

<filter-name>struts</filter-name>

<filter-class>

org.apache.struts2.dispatcher.FilterDispatcher

</filter-class>

<init-param>

<param-name>actionPackages</param-name>

<param-value>user.actions,other.actions</param-value>

</init-param>

</filter>
被配置过的每一个package和它的子package都会被扫描到,看其中哪些类实现了Action或者类名以“Action”结尾,然后注解就会被加入到运行时配置中去。如果没有使用namespace注解的话,那么命名空间就会由package名来生成
生活 2010-03-03
  • 打赏
  • 举报
回复
没人回答你。我顶你去第一页吧、

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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