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

新手使用SSH框架,发现表单提交的数据在action类中全部为null
本人是新手绝对的新手 不是计算机专业出身,完全自学了SSH,第一次将自己的所学集中起来凭着自己的感觉做一个小demo来玩,但是发现一个问题那就是,jsp表单中提交的一些数据,到了相应的action中全部为null,百思不得其解,我本人不在软件公司上班,从事的行业也不是软件行业所以找不到大牛帮我解决问题,现在求助各位论坛高手帮忙。
不罗嗦上代码:
HTML code

<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'addNewBasicUser.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
  
  <body>
    <form action="rootuser/addOneNewBranch" method="post">
        用户名:<input type="text" name="username"/><br/>
        密码:<input type="text" name="password"/><br/>
        支行名称:<input type="text" name="branchbankname"/><br/>
        <input type="submit" value="提交"/>
    </form>
  </body>
</html>


这是对应的action类
Java code

package com.actions;

import javax.annotation.Resource;

import com.dao.interfaceImp.BasicUserDaoImp;
import com.xu.model.BasicUser;
import com.xu.utils.MD5;

public class AddNewBranchBank {
    private String username;
    private String password;
    private String branchbankname;
    private BasicUserDaoImp budi;
    public BasicUserDaoImp getBudi() {
        return budi;
    }
    @Resource(name="BasicUserDaoImp")
    public void setBudi(BasicUserDaoImp budi) {
        this.budi = budi;
    }
    public String 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 getBranchbankname() {
        return branchbankname;
    }
    public void setBranchbankname(String branchbankname) {
        this.branchbankname = branchbankname;
    }

    public String execute(){
        System.out.println(branchbankname+":"+username+":"+password);
        try{
        BasicUser bu = new BasicUser();
        bu.setBranchBankName(branchbankname);
        bu.setUsername(username);
        bu.setPassword(MD5.encrypeMd5(password));
        budi.addNewBasicUser(bu);
        } catch(Exception e){
            e.printStackTrace();
            return "input";
        }
        return "success";
    }
}


这是相关的struts配置
HTML code

<package name="rootuser" namespace="/rootuser" extends="struts-default">
            <interceptors>
        <interceptor name="rootUserTypeCheck" class=&quo