问题描述
- JSP用JAVABEAN传整型值时,如果数值为一位,接收到的值为0,两位以上的值正常。
-
现象如题,环境为MYECLIPSE和TOMCAT6,代码如下:
提交数据的文件department_add.jsp:
<%@ page contentType="text/html" pageEncoding = "GBK"%>
<%@ page import="com.lb.teashop.factory.*,com.lb.teashop.vo.*"%>连锁店信息维护
<% request.setCharacterEncoding("GBK"); //解决中文乱码问题 %>添加连锁店
<%
String id = request.getParameter("id");
if(!(null == id || "".equals(id))){ //指定code时,显示对应信息
try{
DepartmentBean dpt=DAOFactory.getDepartmentDAOInstance().findDepartmentById(Integer.parseInt(id));
//out.println("dgc_code:" + dpt.getName());
department = dpt;
//out.println("department_id:" + department.getId());
%>
店名:
<%=department.getAddress()%><%=department.getErrorMsg("errAddress")%>
电话: <%
}catch(Exception e){
e.printStackTrace();
}
}else{ //未指定code时,显示空白录入界面。
%>
连锁店名称: <%=department.getErrorMsg("errName")%>
拼音码: <%=department.getErrorMsg("errPy_code")%>
地址: <%=department.getErrorMsg("errPy_code")%>
电话: <%=department.getErrorMsg("errPhone")%>
传真: <%=department.getErrorMsg("errFax")%>
<%
}
%>JAVABEAN文件DepartmentBean.java:
/**- */
package com.lb.teashop.vo;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;/**
- @author Administrator
*
/
public class DepartmentBean implements Serializable{
/*- */
private static final long serialVersionUID = 1L;
private int id;
private String name;
private String py_code;
private String address;
private String phone;
private String fax;
private int apply_page_sn;
private int page_sn;
private Maperrors=null; //声明一个保存全部错误信息的Map集合
public DepartmentBean(){
//this.code="";
this.name="";
this.py_code="";
this.errors = new HashMap(); //实例化Map对象,保存错误信息
}public boolean isValidate(){ //数据验证操作
boolean flag = true;
// //System.out.println(this.name);
// //System.out.println(this.comment);
// if(this.name==null || "".equals(this.name)){
// flag = false;
// //System.out.print(this.name);
// errors.put("errName", "请输入商品类别名称。"); //保存错误信息
// }
// if(this.py_code==null || "".equals(this.py_code)){
// flag = false;
// errors.put("errComment", "请输入规格描述,长度不超过150个汉字。");
// }else if(this.py_code.length()>15){
// flag = false;
// //System.out.println(this.specification.length());
// errors.put("errComment", "规格描述是不超过150个字的中文。");
// }
return flag;
}
public String getErrorMsg(String key){
String value = this.errors.get(key);
return value == null?"":value; //返回value对应的内容
}/**
- @return the id
*/
public int getId() {
return id;
}
/**
- @param id the id to set
*/
public void setId(int id) {
this.id = id;
}
/**
- @return the name
*/
public String getName() {
return name;
}
/**
- @param name the name to set
*/
public void setName(String name) {
this.name = name;
}
/**
- @return the py_code
*/
public String getPy_code() {
return py_code;
}
/**
- @param py_code the py_code to set
*/
public void setPy_code(String py_code) {
this.py_code = py_code;
}
/**
- @return the address
*/
public String getAddress() {
return address;
}
/**
- @param address the address to set
*/
public void setAddress(String address) {
this.address = address;
}
/**
- @return the phone
*/
public String getPhone() {
return phone;
}
/**
- @param phone the phone to set
*/
public void setPhone(String phone) {
this.phone = phone;
}
/**
- @return the fax
*/
public String getFax() {
return fax;
}
/**
- @param fax the fax to set
*/
public void setFax(String fax) {
this.fax = fax;
}
/**
- @return the apply_page_sn
*/
public int getApply_page_sn() {
return apply_page_sn;
}
/**
- @param apply_page_sn the apply_page_sn to set
*/
public void setApply_page_sn(int apply_page_sn) {
this.apply_page_sn = apply_page_sn;
}
/**
- @return the page_sn
*/
public int getPage_no() {
return page_sn;
}
/**
- @param page_sn the page_sn to set
*/
public void setPage_no(int page_sn) {
this.page_sn = page_sn;
}
- */
}
接收数据的文件department_update_do.jsp:
<%@ page contentType="text/html" pageEncoding = "GBK"%>
<%@ page import="com.lb.teashop.factory.*" %>
/jsp:useBean
/jsp:setProperty连锁店信息维护
<% request.setCharacterEncoding("GBK"); //解决中文乱码问题 %>
添加连锁店<%=department.getId() %>
<%=department.getName() %>
<%=department.getAddress() %>
<%=department.getPhone() %>
<%=department.getFax() %>
<%=department.getApply_page_sn() %>
<%
if(department.isValidate()){
try{
if(DAOFactory.getDepartmentDAOInstance().doUpdateDepartment(department)>0 ){
%>
商品信息修改成功!
<%
response.setHeader("refresh","2;URL=department_list.jsp");
}else{
%>
商品信息修改失败!
<%
response.setHeader("refresh","2;URL=department_add.jsp?id="+department.getId());
}
}catch(Exception e){
e.printStackTrace(); //在Tomcat后台打印
}
}else{
%>
/jsp:forward
<%
//response.setHeader("refresh","2;URL=department_add.jsp");
}
%>全部的整型变量如果小于10,接收文件看到的都为0,大于等于10的都没问题。求大牛指点迷津!非常感谢!
- */