日期:2014-05-17  浏览次数:20756 次

action无法获取<s:form>的输入

login.jsp
HTML code

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login</title>
</head>
<body>
    <s:form action="authority">
        <s:textfield name="username" key="user" />
        <s:textfield name="password" key="pass" />
        <s:submit key="login" />
    </s:form>
</body>
</html>




AuthorityAction.java
Java code

public class AuthorityAction extends ActionSupport {

    private static final long serialVersionUID = 6397739796446922974L;

    public static Logger logger = LoggerFactory
            .getLogger(AuthorityAction.class);

    String username = "";
    String password = "";
    String tip;

    public String getUsername() {

        logger.debug("getUsername");
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getTip() {
        return tip;
    }

    public void setTip(String tip) {
        this.tip = tip;
    }

    public String execute() throws Exception {

        logger.debug("开始执行");

        logger.debug("username is " + username); //username得不到
        return SUCCESS;
    }
}



页面提交后,后台得不到输入。

请问是怎么回事?

------解决方案--------------------
不好意思呀 我没有过细看

你用的 是struts2 那就不用 写成 实体.属性 这种方式了 就直接写属性

是你的<s:form action="authority"> 提交方式有问题 这种方式是 get 提交方式
你应该用 <s:form action="authority" method="post"> 这种方式提交 


------解决方案--------------------
Java code

    public String execute() throws Exception {

      system.out.print(getUsername());
        return SUCCESS;
    }