如何使用jsp、js、JavaBean、Java业务类在mysql中添加数据,
通过client.jsp文件,我调用saveClient()mtd进行验证-->代码--> Clients.java pojo文件如何使用jsp、js、JavaBean、Java业务类在mysql中添加数据,,java,mysql,hibernate,jsp,struts2,Java,Mysql,Hibernate,Jsp,Struts2,通过client.jsp文件,我调用saveClient()mtd进行验证-->代码--> Clients.java pojo文件 package org.savvy.tsman.pojos; import java.sql.Timestamp; import java.util.HashSet; import java.util.Set; /** * Clients entity. @author MyEclipse Persistence Tools */ public class
package org.savvy.tsman.pojos;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;
/**
* Clients entity. @author MyEclipse Persistence Tools
*/
public class Clients implements java.io.Serializable {
// Fields
private Integer clientid;
private ClientTypesMaster clientTypesMaster;
private AdsMaster adsMaster;
private Integer clientno;
private String firstname;
private String lastname;
private String email;
private String contactno;
private String address;
private String website;
private Integer createdBy;
private Timestamp createdDate;
private Integer modifiedBy;
private Timestamp modifiedDate;
private Set jobses = new HashSet(0);
// Constructors
/** default constructor */
public Clients() {
}
/** minimal constructor */
public Clients(ClientTypesMaster clientTypesMaster, String firstname,
String email, Timestamp createdDate, Timestamp modifiedDate) {
this.clientTypesMaster = clientTypesMaster;
this.firstname = firstname;
this.email = email;
this.createdDate = createdDate;
this.modifiedDate = modifiedDate;
}
/** full constructor */
public Clients(ClientTypesMaster clientTypesMaster, AdsMaster adsMaster,
Integer clientno, String firstname, String lastname, String email,
String contactno, String address, String website,
Integer createdBy, Timestamp createdDate, Integer modifiedBy,
Timestamp modifiedDate, Set jobses) {
this.clientTypesMaster = clientTypesMaster;
this.adsMaster = adsMaster;
this.clientno = clientno;
this.firstname = firstname;
this.lastname = lastname;
this.email = email;
this.contactno = contactno;
this.address = address;
this.website = website;
this.createdBy = createdBy;
this.createdDate = createdDate;
this.modifiedBy = modifiedBy;
this.modifiedDate = modifiedDate;
this.jobses = jobses;
}
// Property accessors
public Integer getClientid() {
return this.clientid;
}
public void setClientid(Integer clientid) {
this.clientid = clientid;
}
public ClientTypesMaster getClientTypesMaster() {
return this.clientTypesMaster;
}
public void setClientTypesMaster(ClientTypesMaster clientTypesMaster) {
this.clientTypesMaster = clientTypesMaster;
}
public AdsMaster getAdsMaster() {
return this.adsMaster;
}
public void setAdsMaster(AdsMaster adsMaster) {
this.adsMaster = adsMaster;
}
public Integer getClientno() {
return this.clientno;
}
public void setClientno(Integer clientno) {
this.clientno = clientno;
}
public String getFirstname() {
return this.firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return this.lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public String getContactno() {
return this.contactno;
}
public void setContactno(String contactno) {
this.contactno = contactno;
}
public String getAddress() {
return this.address;
}
public void setAddress(String address) {
this.address = address;
}
public String getWebsite() {
return this.website;
}
public void setWebsite(String website) {
this.website = website;
}
public Integer getCreatedBy() {
return this.createdBy;
}
public void setCreatedBy(Integer createdBy) {
this.createdBy = createdBy;
}
public Timestamp getCreatedDate() {
return this.createdDate;
}
public void setCreatedDate(Timestamp createdDate) {
this.createdDate = createdDate;
}
public Integer getModifiedBy() {
return this.modifiedBy;
}
public void setModifiedBy(Integer modifiedBy) {
this.modifiedBy = modifiedBy;
}
public Timestamp getModifiedDate() {
return this.modifiedDate;
}
public void setModifiedDate(Timestamp modifiedDate) {
this.modifiedDate = modifiedDate;
}
public Set getJobses() {
return this.jobses;
}
public void setJobses(Set jobses) {
this.jobses = jobses;
}
}
package org.savvy.tsman.pojos;
import java.util.HashSet;
import java.util.Set;
/**
* ClientTypesMaster entity. @author MyEclipse Persistence Tools
*/
public class ClientTypesMaster implements java.io.Serializable {
// Fields
private Integer typeId;
private String typeName;
private Set clientses = new HashSet(0);
// Constructors
/** default constructor */
public ClientTypesMaster() {
}
/** minimal constructor */
public ClientTypesMaster(String typeName) {
this.typeName = typeName;
}
/** full constructor */
public ClientTypesMaster(String typeName, Set clientses) {
this.typeName = typeName;
this.clientses = clientses;
}
// Property accessors
public Integer getTypeId() {
return this.typeId;
}
public void setTypeId(Integer typeId) {
this.typeId = typeId;
}
public String getTypeName() {
return this.typeName;
}
public void setTypeName(String typeName) {
this.typeName = typeName;
}
public Set getClientses() {
return this.clientses;
}
public void setClientses(Set clientses) {
this.clientses = clientses;
}
}
ClientBean文件
package org.savvy.tsman.beans;
public class ClientBean {
private String firstname;
private String lastname;
private String client_Type;
private String adsMaster;
private String client_No;
private String contact_No;
private String email;
private String hear;
private String address;
private String website;
private String Userid;
public String getAdsMaster() {
return adsMaster;
}
public void setAdsMaster(String adsMaster) {
this.adsMaster = adsMaster;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getClient_Type() {
return client_Type;
}
public void setClient_Type(String client_Type) {
this.client_Type = client_Type;
}
public String getClient_No() {
return client_No;
}
public void setClient_No(String client_No) {
this.client_No = client_No;
}
public String getContact_No() {
return contact_No;
}
public void setContact_No(String contact_No) {
this.contact_No = contact_No;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getHear() {
return hear;
}
public void setHear(String hear) {
this.hear = hear;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website = website;
}
public String getUserid() {
return Userid;
}
public void setUserid(String userid) {
Userid = userid;
}
}
ClientsTypesMaster pojo文件
package org.savvy.tsman.pojos;
import java.sql.Timestamp;
import java.util.HashSet;
import java.util.Set;
/**
* Clients entity. @author MyEclipse Persistence Tools
*/
public class Clients implements java.io.Serializable {
// Fields
private Integer clientid;
private ClientTypesMaster clientTypesMaster;
private AdsMaster adsMaster;
private Integer clientno;
private String firstname;
private String lastname;
private String email;
private String contactno;
private String address;
private String website;
private Integer createdBy;
private Timestamp createdDate;
private Integer modifiedBy;
private Timestamp modifiedDate;
private Set jobses = new HashSet(0);
// Constructors
/** default constructor */
public Clients() {
}
/** minimal constructor */
public Clients(ClientTypesMaster clientTypesMaster, String firstname,
String email, Timestamp createdDate, Timestamp modifiedDate) {
this.clientTypesMaster = clientTypesMaster;
this.firstname = firstname;
this.email = email;
this.createdDate = createdDate;
this.modifiedDate = modifiedDate;
}
/** full constructor */
public Clients(ClientTypesMaster clientTypesMaster, AdsMaster adsMaster,
Integer clientno, String firstname, String lastname, String email,
String contactno, String address, String website,
Integer createdBy, Timestamp createdDate, Integer modifiedBy,
Timestamp modifiedDate, Set jobses) {
this.clientTypesMaster = clientTypesMaster;
this.adsMaster = adsMaster;
this.clientno = clientno;
this.firstname = firstname;
this.lastname = lastname;
this.email = email;
this.contactno = contactno;
this.address = address;
this.website = website;
this.createdBy = createdBy;
this.createdDate = createdDate;
this.modifiedBy = modifiedBy;
this.modifiedDate = modifiedDate;
this.jobses = jobses;
}
// Property accessors
public Integer getClientid() {
return this.clientid;
}
public void setClientid(Integer clientid) {
this.clientid = clientid;
}
public ClientTypesMaster getClientTypesMaster() {
return this.clientTypesMaster;
}
public void setClientTypesMaster(ClientTypesMaster clientTypesMaster) {
this.clientTypesMaster = clientTypesMaster;
}
public AdsMaster getAdsMaster() {
return this.adsMaster;
}
public void setAdsMaster(AdsMaster adsMaster) {
this.adsMaster = adsMaster;
}
public Integer getClientno() {
return this.clientno;
}
public void setClientno(Integer clientno) {
this.clientno = clientno;
}
public String getFirstname() {
return this.firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return this.lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
public String getContactno() {
return this.contactno;
}
public void setContactno(String contactno) {
this.contactno = contactno;
}
public String getAddress() {
return this.address;
}
public void setAddress(String address) {
this.address = address;
}
public String getWebsite() {
return this.website;
}
public void setWebsite(String website) {
this.website = website;
}
public Integer getCreatedBy() {
return this.createdBy;
}
public void setCreatedBy(Integer createdBy) {
this.createdBy = createdBy;
}
public Timestamp getCreatedDate() {
return this.createdDate;
}
public void setCreatedDate(Timestamp createdDate) {
this.createdDate = createdDate;
}
public Integer getModifiedBy() {
return this.modifiedBy;
}
public void setModifiedBy(Integer modifiedBy) {
this.modifiedBy = modifiedBy;
}
public Timestamp getModifiedDate() {
return this.modifiedDate;
}
public void setModifiedDate(Timestamp modifiedDate) {
this.modifiedDate = modifiedDate;
}
public Set getJobses() {
return this.jobses;
}
public void setJobses(Set jobses) {
this.jobses = jobses;
}
}
package org.savvy.tsman.pojos;
import java.util.HashSet;
import java.util.Set;
/**
* ClientTypesMaster entity. @author MyEclipse Persistence Tools
*/
public class ClientTypesMaster implements java.io.Serializable {
// Fields
private Integer typeId;
private String typeName;
private Set clientses = new HashSet(0);
// Constructors
/** default constructor */
public ClientTypesMaster() {
}
/** minimal constructor */
public ClientTypesMaster(String typeName) {
this.typeName = typeName;
}
/** full constructor */
public ClientTypesMaster(String typeName, Set clientses) {
this.typeName = typeName;
this.clientses = clientses;
}
// Property accessors
public Integer getTypeId() {
return this.typeId;
}
public void setTypeId(Integer typeId) {
this.typeId = typeId;
}
public String getTypeName() {
return this.typeName;
}
public void setTypeName(String typeName) {
this.typeName = typeName;
}
public Set getClientses() {
return this.clientses;
}
public void setClientses(Set clientses) {
this.clientses = clientses;
}
}
我使用的是Mysql数据库,其结构如下
对于客户端类型,我有两个表1,称为client\u types\u master,有两列typeid和typename
另一个表名是clients,它有14列,顺序与下面给出的相同
客户id、客户号、客户类型、名、姓、电子邮件、联系人号、地址、网站、广告id、创建人、创建日期、修改人、修改日期
现在问题是,,
我可以登录,前端验证工作正常,但当我填写所有数据并单击“保存”按钮时,它会将警报消息显示为无错误,正如我在js文件中给出的那样,但当我单击警报消息框的“确定”时,数据未添加到数据库,浏览器将挂起显示,请稍候。对不起,我的问题是,如何使用jsp、js、JavaBean、Java业务类、struts和hibernate在mysql中添加数据?我可以在hibernate部分帮助您…好的,先生,那么您需要我添加hibernate文件吗?这个编辑建议的意思是什么,我不明白这个概念。@mounika你在使用xml进行映射吗?
package org.savvy.tsman.beans;
public class ClientBean {
private String firstname;
private String lastname;
private String client_Type;
private String adsMaster;
private String client_No;
private String contact_No;
private String email;
private String hear;
private String address;
private String website;
private String Userid;
public String getAdsMaster() {
return adsMaster;
}
public void setAdsMaster(String adsMaster) {
this.adsMaster = adsMaster;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getClient_Type() {
return client_Type;
}
public void setClient_Type(String client_Type) {
this.client_Type = client_Type;
}
public String getClient_No() {
return client_No;
}
public void setClient_No(String client_No) {
this.client_No = client_No;
}
public String getContact_No() {
return contact_No;
}
public void setContact_No(String contact_No) {
this.contact_No = contact_No;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getHear() {
return hear;
}
public void setHear(String hear) {
this.hear = hear;
}
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getWebsite() {
return website;
}
public void setWebsite(String website) {
this.website = website;
}
public String getUserid() {
return Userid;
}
public void setUserid(String userid) {
Userid = userid;
}
}
package org.savvy.tsman.pojos;
import java.util.HashSet;
import java.util.Set;
/**
* ClientTypesMaster entity. @author MyEclipse Persistence Tools
*/
public class ClientTypesMaster implements java.io.Serializable {
// Fields
private Integer typeId;
private String typeName;
private Set clientses = new HashSet(0);
// Constructors
/** default constructor */
public ClientTypesMaster() {
}
/** minimal constructor */
public ClientTypesMaster(String typeName) {
this.typeName = typeName;
}
/** full constructor */
public ClientTypesMaster(String typeName, Set clientses) {
this.typeName = typeName;
this.clientses = clientses;
}
// Property accessors
public Integer getTypeId() {
return this.typeId;
}
public void setTypeId(Integer typeId) {
this.typeId = typeId;
}
public String getTypeName() {
return this.typeName;
}
public void setTypeName(String typeName) {
this.typeName = typeName;
}
public Set getClientses() {
return this.clientses;
}
public void setClientses(Set clientses) {
this.clientses = clientses;
}
}