将jsp注册页面中的信息添加到数据库出现问题
jsp代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
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 'register.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="RegistLogin/registerAction" name="f3" method="get" onsubmit="validate();">
用户名:<input type="text" name="registerinfo.userName" id="userInf"><br>
密码:<input type="password" nmae="registerinfo.passWord"><br>
密码确认:<input type="password" name="registerinfo.pConfirm"><br>
email:<input type="text" name="registerinfo.email"><br>
<input type="submit" name="s1" value="submit" >
<input type="reset" name="s2" value="reset">
</form>
</body>
</html>
registerinfo对象的类如下:
public class RegisterInfo {
public String userName;
public String passWord;
public String pConfirm;
public String email;
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 getpConfirm() {
return pConfirm;
}
public void setpConfirm(String pConfirm) {
this.pConfirm = pConfirm;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
action代码如下:
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import whut.ec.webwork.model.DatabaseConnection;
import whut.ec.webwork.model.RegisterInfo;
import com.opensymphony.xwork2.ActionSupport;
public class RegisterLoginDeal extends ActionSupport{
private RegisterInfo registerinfo;
public RegisterInfo getRegisterinfo() {
return registerinfo;
}
public void setRegisterinfo(RegisterInfo registerinfo) {
this.registerinfo = registerinfo;
}
public String register() throws ClassNotFoundException, SQLException{
String sql="insert into register(username,password,pconfirm,email) values("+"'"+registerinfo.getUserName()+"','"+registerinfo.getPassWord()+"','"
+registerinfo.getpConfirm()+"','"+registerinfo.getEmail()+"')";
Connection conn=DatabaseConnection.getconnection();
Statement sta=conn.createStatement();
sta.executeUpdate(sql);
System.out.println(registerinfo.getPassWord());
return "register";
}
public String load(){
return "loading";
}
}
struts中的配置啊,什么的一切都正常,就是数据库中发现,password的值为null!表单中其它变量的值都可以存放到数据库中!
[解决办法]
用户名:<input type="text" name="registerinfo.userName" id="userInf"><br>
密码:<input type="password" nmae="registerinfo.passWord"><br>
密码确认:<input type="password" name="registerinfo.pConfirm"><br