首页上一页 1 下一页尾页 5 条记录 1/1页
jsp程序开发范例宝典 例子129的一个小问题
发表在JavaWeb图书答疑
2008-03-04
是否精华
是
否
版块置顶:
是
否
<P>我把本例129的save.jsp页面的代码贴出来:</P>
<P><%@ page language="java" contentType="text/html; charset=GB18030"<BR> pageEncoding="GB18030"%><BR><jsp:directive.page import="java.sql.ResultSet" /><BR><jsp:directive.page import="java.sql.Connection" /><BR><jsp:directive.page import="java.sql.Statement" /><BR><jsp:directive.page import="java.sql.DriverManager" /><BR><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><BR><%<BR> request.setCharacterEncoding("GB18030");<BR> String maxId = null;<BR> int ID = 0;<BR> if (request.getParameter("spname") != null) {<BR> String spname = request.getParameter("spname");<BR> String cs = request.getParameter("cs");<BR> String gg = request.getParameter("gg");<BR> String bz = request.getParameter("bz");<BR> String dw = request.getParameter("dw");<BR> String dj = request.getParameter("dj");<BR> String sl = request.getParameter("sl");<BR> String je = request.getParameter("je");<BR> String cgdate = request.getParameter("cgdate");<BR> String memo = request.getParameter("memo");<BR> if (spname == null || cs == null || gg == null || bz == null<BR> || dw == null || dj == null || sl == null || je == null) {<BR>%><BR><script language="javascript"><BR> alert("您必须全部填写")<BR> history.back(1)<BR> </script><BR><%<BR> }<BR> dj = dj + "元";<BR> sl = sl + dw;<BR> je = je + "元";<BR> //连接数据库<BR> Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");<BR> Connection conn = DriverManager<BR> .getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_database05;user=sa");<BR> Statement st = conn.createStatement();<BR> String sql = "select max(id) as id from tab_cgd where cgdate='"<BR> + cgdate + "'";<BR> ResultSet rs = st.executeQuery(sql);<BR> if (rs.next())<BR> maxId = rs.getString(1);<BR> if (maxId == null)<BR> maxId = "CG" + cgdate.replace("-", "") + "00001";<BR> else {<BR> maxId = maxId.trim();<BR> ID = Integer.parseInt(maxId.substring(maxId.length() - 5));<BR> maxId = maxId.substring(0, maxId.length() - 5)<BR> + String.format("%05d", ID + 1);<BR> }<BR> sql = "insert into tab_cgd(id,spname,cs,gg,bz,dw,dj,sl,je,cgdate,memo) values('"<BR> + maxId+ "','"+ spname+ "','"+ cs+ "','"+ gg+ "','"+ bz+ "','"+ dw+ "','"+ dj<BR> + "','"+ sl+ "','" + je + "','" + cgdate + "','" + memo + "')";<BR> st.executeUpdate(sql);<BR> rs.close();<BR> st.close();<BR> conn.close();<BR>%><BR><script language="javascript"><BR> alert("采购信息保存成功!");<BR> window.location.href="spcg_xianxi.jsp";<BR></script><BR><%<BR>}<BR>%></P>
<P>发生的是下面的错误:从前台页面index.jsp接收表单传递过来的数据,在if语句判断有空的时候,弹出提示“您必须全部填写!”,点“确定”之后,回到上一个页面index.jsp。但是,为什么也能把数据保存到数据库中呢?如果数据有空,应该不能保存的。敬请赐教!</P>
<P>把spname == "" || cs == "" || gg == "" || bz == ""<BR> || dw == ""|| dj == "" || sl == "" || je == ""也不行。同样的错误</P>
<P><%@ page language="java" contentType="text/html; charset=GB18030"<BR> pageEncoding="GB18030"%><BR><jsp:directive.page import="java.sql.ResultSet" /><BR><jsp:directive.page import="java.sql.Connection" /><BR><jsp:directive.page import="java.sql.Statement" /><BR><jsp:directive.page import="java.sql.DriverManager" /><BR><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><BR><%<BR> request.setCharacterEncoding("GB18030");<BR> String maxId = null;<BR> int ID = 0;<BR> if (request.getParameter("spname") != null) {<BR> String spname = request.getParameter("spname");<BR> String cs = request.getParameter("cs");<BR> String gg = request.getParameter("gg");<BR> String bz = request.getParameter("bz");<BR> String dw = request.getParameter("dw");<BR> String dj = request.getParameter("dj");<BR> String sl = request.getParameter("sl");<BR> String je = request.getParameter("je");<BR> String cgdate = request.getParameter("cgdate");<BR> String memo = request.getParameter("memo");<BR> if (spname == null || cs == null || gg == null || bz == null<BR> || dw == null || dj == null || sl == null || je == null) {<BR>%><BR><script language="javascript"><BR> alert("您必须全部填写")<BR> history.back(1)<BR> </script><BR><%<BR> }<BR> dj = dj + "元";<BR> sl = sl + dw;<BR> je = je + "元";<BR> //连接数据库<BR> Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");<BR> Connection conn = DriverManager<BR> .getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=db_database05;user=sa");<BR> Statement st = conn.createStatement();<BR> String sql = "select max(id) as id from tab_cgd where cgdate='"<BR> + cgdate + "'";<BR> ResultSet rs = st.executeQuery(sql);<BR> if (rs.next())<BR> maxId = rs.getString(1);<BR> if (maxId == null)<BR> maxId = "CG" + cgdate.replace("-", "") + "00001";<BR> else {<BR> maxId = maxId.trim();<BR> ID = Integer.parseInt(maxId.substring(maxId.length() - 5));<BR> maxId = maxId.substring(0, maxId.length() - 5)<BR> + String.format("%05d", ID + 1);<BR> }<BR> sql = "insert into tab_cgd(id,spname,cs,gg,bz,dw,dj,sl,je,cgdate,memo) values('"<BR> + maxId+ "','"+ spname+ "','"+ cs+ "','"+ gg+ "','"+ bz+ "','"+ dw+ "','"+ dj<BR> + "','"+ sl+ "','" + je + "','" + cgdate + "','" + memo + "')";<BR> st.executeUpdate(sql);<BR> rs.close();<BR> st.close();<BR> conn.close();<BR>%><BR><script language="javascript"><BR> alert("采购信息保存成功!");<BR> window.location.href="spcg_xianxi.jsp";<BR></script><BR><%<BR>}<BR>%></P>
<P>发生的是下面的错误:从前台页面index.jsp接收表单传递过来的数据,在if语句判断有空的时候,弹出提示“您必须全部填写!”,点“确定”之后,回到上一个页面index.jsp。但是,为什么也能把数据保存到数据库中呢?如果数据有空,应该不能保存的。敬请赐教!</P>
<P>把spname == "" || cs == "" || gg == "" || bz == ""<BR> || dw == ""|| dj == "" || sl == "" || je == ""也不行。同样的错误</P>