首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

jsp表单的值到Servlet时,给javabean赋值不成功。该怎么解决

2012-04-11 
jsp表单的值到Servlet时,给javabean赋值不成功。JSP表单%@ page languagejava importjava.util.* pa

jsp表单的值到Servlet时,给javabean赋值不成功。
JSP表单

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="Bean.*" %>
<%@ page import="java.util.*" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 
  <title>信息保存</title>

  </head>

<body>
<form name="form1" action="xinxibaocunServlet" method="post">
<table align="center" border ="1" width="80%" height="80%">
<tr> 
<td colspan="2"><input type="button" name="Close" onclick="window.close();"value="关闭">
<input type="submit" name="Save" value="保存">
<input type="reset" name="reset" value="重填">
</td>
</tr>
<tr>
<td>系统名:</td>
<td><input type="text" name="SystemName" size="13"></td>
<td>中文名:</td>
<td><input type="text" name="ChineseName" size="13"></td>
<td>人员姓名简称:</td>
<td><input type="text" name="NameShort" size="13"></td>
</tr>
<tr>
<td>所属单位:</td>
<td>
<select name="Unit">
<option selected="" value="0">--请选择--</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</td>
<td>所属部门:</td>
<td>
<select name="Department">
<option selected="" value="0">--请选择--</option>
<option value="1">a</option>
<option value="2">b</option>
<option value="3">c</option>
</select>
</td>
<td>出生日期:</td>
<td><input type="text" name="Data" size="13"></td>
</tr>
<tr>
<td>职务:</td>
<td><input type="text" name="Job" size="13"></td>
<td>是否主持工作:</td>
<td>
<select name="HostWork">
<option selected="" value="0">--请选择--</option>
<option value="1">是</option>
<option value="2">否</option>
</select>
</td>
<td>是否单位帐号:</td>
<td>
<select name="UnitAccounts">
<option selected="" value="0">--请选择--</option>
<option value="1">是</option>
<option value="2">否</option>
</select>
</td>
</tr>
<tr>
<td>家庭电话号码:</td>
<td><input type="text" name="HomePhoneNumber" size="13"></td>
<td>手机号码:</td>
<td><input type="text" name="MobileNumber" size="13"></td>
<td>虚拟号:</td>
<td><input type="text" name="VirtualPageNumber" size="13"></td>
</tr>
<tr>
<td>小灵通:</td>


<td><input type="text" name="LittleSmart" size="13"></td>
<td>邮箱地址:</td>
<td><input type="text" name="Email" size="13"></td>
<td>传真号:</td>
<td><input type="text" name="FaxNumber" size="13"></td>
</tr>
<tr>
<td>办公室电话:</td>
<td><input type="text" name="OfficePhone" size="13"></td>
<td>可发送的短消息条数:</td>
<td><input type="text" name="ShortMessageNnumber" size="13"></td>
<td>邮件限额:</td>
<td><input type="text" name="EmailNumber" size="13"></td>
</tr>
<tr>
<td>帐号状态:</td>
<td>
<select name="AccountStatus">
<option selected="" value="0">--请选择--</option>
<option value="1">激活</option>
<option value="2">冻结</option>
</select>
</td>
<td>排序号:</td>
<td colspan="3"><input type="text" name="SequenceNumber" size="13"></td>
</tr>
<tr>
<td>备注:</td>
<td colspan="5" >
<textarea name="Remark" ></textarea>
</td>
</tr>
</table>
</form>
</body>
</html>

JAVABEAN

package Bean;

public class SysBean {
private String SystemName;
private String ChineseName;
private String NameShort;
private String Unit;
private String Department;
private String Data;
private String Job;
private String HostWork;
private String UnitAccounts;
private String HomePhoneNumber;
private String MobileNumber;
private String VirtualPageNumber;
private String LittleSmart;
private String Email;
private String FaxNumber;
private String OfficePhone;
private String ShortMessageNnumber;
private String EmailNumber;
private String AccountStatus;
private String SequenceNumber;
private String Remark;
public String getSystemName() {
return SystemName;
}
public void setSystemName(String systemName) {
this.SystemName = systemName;
}
public String getChineseName() {
return ChineseName;
}
public void setChineseName(String chineseName) {
this.ChineseName = chineseName;
}
public String getNameShort() {
return NameShort;
}
public void setNameShort(String nameShort) {
this.NameShort = nameShort;
}
public String getUnit() {
return Unit;
}
public void setUnit(String unit) {
this.Unit = unit;
}
public String getDepartment() {
return Department;
}
public void setDepartment(String department) {
this.Department = department;
}
public String getData() {
return Data;
}
public void setData(String data) {
this.Data = data;
}
public String getJob() {
return Job;
}
public void setJob(String job) {
this.Job = job;
}
public String getHostWork() {
return HostWork;
}
public void setHostWork(String hostWork) {
this.HostWork = hostWork;
}
public String getUnitAccounts() {
return UnitAccounts;
}
public void setUnitAccounts(String unitAccounts) {
this.UnitAccounts = unitAccounts;
}
public String getHomePhoneNumber() {
return HomePhoneNumber;
}
public void setHomePhoneNumber(String homePhoneNumber) {
this.HomePhoneNumber = homePhoneNumber;


}
public String getMobileNumber() {
return MobileNumber;
}
public void setMobileNumber(String mobileNumber) {
this.MobileNumber = mobileNumber;
}
public String getVirtualPageNumber() {
return VirtualPageNumber;
}
public void setVirtualPageNumber(String virtualPageNumber) {
this.VirtualPageNumber = virtualPageNumber;
}
public String getLittleSmart() {
return LittleSmart;
}
public void setLittleSmart(String littleSmart) {
this.LittleSmart = littleSmart;
}
public String getEmail() {
return Email;
}
public void setEmail(String email) {
this.Email = email;
}
public String getFaxNumber() {
return FaxNumber;
}
public void setFaxNumber(String faxNumber) {
this.FaxNumber = faxNumber;
}
public String getOfficePhone() {
return OfficePhone;
}
public void setOfficePhone(String officePhone) {
this.OfficePhone = officePhone;
}
public String getShortMessageNnumber() {
return ShortMessageNnumber;
}
public void setShortMessageNnumber(String shortMessageNnumber) {
this.ShortMessageNnumber = shortMessageNnumber;
}
public String getEmailNumber() {
return EmailNumber;
}
public void setEmailNumber(String emailNumber) {
this.EmailNumber = emailNumber;
}
public String getAccountStatus() {
return AccountStatus;
}
public void setAccountStatus(String accountStatus) {
this.AccountStatus = accountStatus;
}
public String getSequenceNumber() {
return SequenceNumber;
}
public void setSequenceNumber(String sequenceNumber) {
this.SequenceNumber = sequenceNumber;
}
public String getRemark() {
return Remark;
}
public void setRemark(String remark) {
this.Remark = remark;
}



Servlet

}

public class xinxibaocunServlet extends HttpServlet{



private static final long serialVersionUID = 1L;

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

request.setCharacterEncoding("utf-8");

// 插入信息 
SysBean user = new SysBean();
try {
BeanUtils.populate(user, request.getParameterMap());
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
现在我想把表单的值转到user中,可是显示为空。

[解决办法]
user, request.getParameterMap()这两对象的结构不一样,不能这样用BeanUtils吧?

你先看看request.getParameterMap()里面有值么?

热点排行