struts 救助
来源:百度知道 编辑:UC知道 时间:2024/06/13 22:44:15
struts 怎么往数据库里插数据????
jsp页面
<body>
<html:form action="/user">
username : <html:text property="username"/><html:errors property="username"/><br/>
age : <html:text property="age"/><html:errors property="age"/><br/>
password : <html:text property="password"/><html:errors property="password"/><br/>
<html:submit/><html:cancel/>
</html:form>
</body>
===================
user
public int id ;
public String username ;
public String password ;
public int age ;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username =
jsp页面
<body>
<html:form action="/user">
username : <html:text property="username"/><html:errors property="username"/><br/>
age : <html:text property="age"/><html:errors property="age"/><br/>
password : <html:text property="password"/><html:errors property="password"/><br/>
<html:submit/><html:cancel/>
</html:form>
</body>
===================
user
public int id ;
public String username ;
public String password ;
public int age ;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username =
UserForm与User基本一致。你只需要把UserForm的值赋给User就可以啦。。
User user = new User();
user.setUsername(userForm.getUsername());
user.setPassword(userForm.getPassword());
Userdao userdao = new Userdao();
userdao.insert(user);
基本就是这样。。
User user = new User();
String username = userForm.get("username");
……
user.setUsername(username);
……
userdao.insert(user);