提交时的菜鸟问题 第一次存盘编译时都没问题,无论输入数字还是字符问题是输入字符后,提交opr.jsp处理,提示非法字符(说明判断无误)回到login.jsp再输入数字,提交opr.jsp处理仍然提示非法字符 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 log.jsp<html><head><title>step1</title></head><%@page contentType="text/html; charset=gb2312" %><% out.println("Pls input information!\n");%><body><form type=POST action="updata.jsp"><br><b>ID: </b><input type="text" name="id1"><br><b>名称:</b><input type="text" name="name1"><br><b>值: </b><t><input type="text" name="value1"></br><input type="submit" value="登录"><input type="reset" value=" 刷新"></body></html>updata.jsp<%@page contentType="text/html; charset=gb2312" %><%@page language="java" %><%@page import="java.sql.*" %> <%! boolean islegal=true; String idString = ""; Integer idInteger = new Integer(0); int id2 = 0; String name2 = ""; String value2 = "";%><% idString = request.getParameter("id1"); for(int i=0;i<idString.length();i++) { if(((char)idString.charAt(i)>'9')||((char)idString.charAt(i)<'0')) { islegal = false; break; } } if(islegal) { idInteger = java.lang.Integer.valueOf(idString); id2 = idInteger.intValue(); name2 = request.getParameter("name1"); value2 = request.getParameter("value1"); }%><html><head><title>step2</title></head><body><form method="post" action="delrelog.jsp"><% if(islegal) { } out.print("<br>" +"<input type='submit' name='delete' value='删除'>" +"</form>"); out.print("<form method='post' action='addrelog.jsp'>" +"<input type='submit' name='addnew' value='新增'>" +"</form>"); } else { out.print("ID must be numderic"); out.print("<br>" +"</form>" +"<form method='post' action='log.jsp'>" +"<input type='submit' name='relog' value='重新输入'>" +"</form>"); }%><br></body></html> <html><head><title>step1</title></head><%@page contentType="text/html; charset=gb2312" %><% out.println("Pls input information!\n");%><body><form type=POST action="updata.jsp"><br><b>ID: </b><input type="text" name="id1"><br><b>名称:</b><input type="text" name="name1"><br><b>值: </b><t><input type="text" name="value1"></br><input type="submit" value="登录"><input type="reset" value=" 刷新"></body></html><%@page contentType="text/html; charset=gb2312" %><%@page language="java" %><%@page import="java.sql.*" %> <% boolean islegal=true; String idString = ""; Integer idInteger = new Integer(0); int id2 = 0; String name2 = ""; String value2 = "";%><% idString = request.getParameter("id1"); for(int i=0;i<idString.length();i++) { if(((char)idString.charAt(i)>'9')||((char)idString.charAt(i)<'0')) { islegal = false; break; } } if(islegal) { idInteger = java.lang.Integer.valueOf(idString); id2 = idInteger.intValue(); name2 = request.getParameter("name1"); value2 = request.getParameter("value1"); }%><html><head><title>step2</title></head><body><form method="post" action="delrelog.jsp"><% if(islegal) { out.print("<br>" +"<input type='submit' name='delete' value='删除'>" +"</form>"); out.print("<form method='post' action='addrelog.jsp'>" +"<input type='submit' name='addnew' value='新增'>" +"</form>"); } else { out.print("ID must be numderic"); out.print("<br>" +"</form>" +"<form method='post' action='log.jsp'>" +"<input type='submit' name='relog' value='重新输入'>" +"</form>"); }%><br></body></html>你的代码,我经过调试,没有出现你所说的问题啊。你的opr.jsp呢? 我是想在第二个页面updata.jsp验证输入ID是否数字,否则回到log.jsp现在是输入一次非字符后,回到log.jsp再输入数字仍按非字符处理第一次就输入数字就正确 还是不行,怪哉!而且地址中传递的是正确参数http://localhost:8080/system/updata.jsp?id1=46&name1=fgh&value1=fgj为什么按照错误的id1处理呢? if 中只是以下一些操作,会影响吗?try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:demo"); Statement stmt = con.createStatement(); String sqlLanguageString ="select * from tname";// where wbcss = "+id2 //+" AND headname = " +"'" +name2+"'"+ " AND headvalue = " +"'"+value2+"'"; ResultSet rst = stmt.executeQuery(sqlLanguageString); while(rst.next()) { int outputId = rst.getInt("wbcssid"); Integer outputIdInteger = new Integer(outputId); String outputIdString = outputIdInteger.toString(); String outputHead = rst.getString("headname"); String outputValue = rst.getString("headvalue"); String checkValue = "record" + outputIdString; out.println("<p><input type=checkbox name='recordcheck' value="+outputIdString+">" +"<a href='save.jsp'>"+outputId+outputHead+outputValue); out.println("<br>"); } } catch(ClassNotFoundException e) { System.out.print("ClassNotFoundException occur when connect to database!"); } catch(SQLException e) { System.out.print("SQLException occur when output data!"); } out.print("<br>" +"<input type='submit' name='delete' value='删除'>" +"</form>"); out.print("<form method='post' action='addrelog.jsp'>" +"<input type='submit' name='addnew' value='新增'>" +"</form>"); } <% idString = request.getParameter("id1"); out.println("id1=="+idString) ; for(int i=0;i<idString.length();i++) { if(((char)idString.charAt(i)>'9')||((char)idString.charAt(i)<'0')) { islegal = false; break; } } if(islegal) { idInteger = java.lang.Integer.valueOf(idString); id2 = idInteger.intValue(); out.println("id2=="+id2) ; name2 = request.getParameter("name1"); value2 = request.getParameter("value1"); }%>用上面的代码跟踪一下。 <% idString = request.getParameter("id1"); out.println("id1=="+idString) ;//*** for(int i=0;i<idString.length();i++) { if(((char)idString.charAt(i)>'9')||((char)idString.charAt(i)<'0')) { islegal = false; break; } } out.print(islegal);////*******输出id是数字,islegal is false??? out.println("id1=="+idString) ;//***这里输出的是什么? <% idString = request.getParameter("id1"); islegal=true;//*******I see.But Why must set true here??? for(int i=0;i<idString.length();i++) { if(((char)idString.charAt(i)>'9')||((char)idString.charAt(i)<'0')) { islegal = false; break; 你最是在log.jsp中用js来判断id1值是否是数字,如果是则提交,如果不是,出现提示错误信息,且不能提交,这样在update中就不要判断了,其实是不提昌在下过页面进行判断的。下面提供js函数。//检测是否是整数function isInteger(inputVal) { var iNumber; if (inputVal.length > 0) { iNumber = Number(inputVal); if (isNaN(iNumber)) return false; else if (String(iNumber).indexOf(".") >= 0) return false; } return true;}你在update.jsp中可这样来接收id1的数据。 int id1 = Integer.parseInt(request.getParameter("id1").equals("")?"0":request.getParameter("id1")) ;这样你就不用判断了,直接组合sql进行查询。试试吧。 struts标签的变量比较问题求教 JSP Frame 中嵌套了一个Iframe, IFrame的内容不能显示 在线等....跪求 同一个问题开新贴问高手 把图片以BLOB形式存入ORACLE数据库中。当文件大于3K时。就报错。为什么?(在线急等) 关于网络订单系统! 抽象类不是不能直接实例化吗?可是我们的类库里竟然势力化了,大家帮我看看。。 一个数据集的问题,up …… 启动Tomcat时,出现如下错误,大神帮帮分析哈是什么原因,在此谢过了 求助数组计算问题? 怎样通过将url上的参数传递给xsl 提供国内在nsdaq上市的某特大门户网站核心源代码!
<html>
<head>
<title>step1</title>
</head>
<%@page contentType="text/html; charset=gb2312" %>
<%
out.println("Pls input information!\n");
%>
<body>
<form type=POST action="updata.jsp">
<br>
<b>ID: </b>
<input type="text" name="id1">
<br>
<b>名称:</b>
<input type="text" name="name1">
<br>
<b>值: </b>
<t><input type="text" name="value1">
</br>
<input type="submit" value="登录">
<input type="reset" value=" 刷新">
</body>
</html>
updata.jsp
<%@page contentType="text/html; charset=gb2312" %>
<%@page language="java" %>
<%@page import="java.sql.*" %>
<%! boolean islegal=true;
String idString = "";
Integer idInteger = new Integer(0);
int id2 = 0;
String name2 = "";
String value2 = "";
%><% idString = request.getParameter("id1");
for(int i=0;i<idString.length();i++)
{
if(((char)idString.charAt(i)>'9')||((char)idString.charAt(i)<'0'))
{
islegal = false;
break;
}
}
if(islegal)
{
idInteger = java.lang.Integer.valueOf(idString);
id2 = idInteger.intValue();
name2 = request.getParameter("name1");
value2 = request.getParameter("value1");
}
%>
<html>
<head>
<title>step2</title>
</head>
<body>
<form method="post" action="delrelog.jsp"><% if(islegal)
{
}
out.print("<br>"
+"<input type='submit' name='delete' value='删除'>"
+"</form>");
out.print("<form method='post' action='addrelog.jsp'>"
+"<input type='submit' name='addnew' value='新增'>"
+"</form>");
}
else
{
out.print("ID must be numderic");
out.print("<br>"
+"</form>"
+"<form method='post' action='log.jsp'>"
+"<input type='submit' name='relog' value='重新输入'>"
+"</form>");
}
%><br>
</body>
</html>
<html>
<head>
<title>step1</title>
</head>
<%@page contentType="text/html; charset=gb2312" %>
<%
out.println("Pls input information!\n");
%>
<body>
<form type=POST action="updata.jsp">
<br>
<b>ID: </b>
<input type="text" name="id1">
<br>
<b>名称:</b>
<input type="text" name="name1">
<br>
<b>值: </b>
<t><input type="text" name="value1">
</br>
<input type="submit" value="登录">
<input type="reset" value=" 刷新">
</body>
</html>
<%@page contentType="text/html; charset=gb2312" %>
<%@page language="java" %>
<%@page import="java.sql.*" %>
<% boolean islegal=true;
String idString = "";
Integer idInteger = new Integer(0);
int id2 = 0;
String name2 = "";
String value2 = "";
%><% idString = request.getParameter("id1");
for(int i=0;i<idString.length();i++)
{
if(((char)idString.charAt(i)>'9')||((char)idString.charAt(i)<'0'))
{
islegal = false;
break;
}
}
if(islegal)
{
idInteger = java.lang.Integer.valueOf(idString);
id2 = idInteger.intValue();
name2 = request.getParameter("name1");
value2 = request.getParameter("value1");
}
%>
<html>
<head>
<title>step2</title>
</head>
<body>
<form method="post" action="delrelog.jsp"><% if(islegal)
{
out.print("<br>"
+"<input type='submit' name='delete' value='删除'>"
+"</form>");
out.print("<form method='post' action='addrelog.jsp'>"
+"<input type='submit' name='addnew' value='新增'>"
+"</form>");
}
else
{
out.print("ID must be numderic");
out.print("<br>"
+"</form>"
+"<form method='post' action='log.jsp'>"
+"<input type='submit' name='relog' value='重新输入'>"
+"</form>");
}
%><br>
</body>
</html>你的代码,我经过调试,没有出现你所说的问题啊。
你的opr.jsp呢?
现在是输入一次非字符后,回到log.jsp再输入数字仍按非字符处理
第一次就输入数字就正确
http://localhost:8080/system/updata.jsp?id1=46&name1=fgh&value1=fgj
为什么按照错误的id1处理呢?
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:demo");
Statement stmt = con.createStatement();
String sqlLanguageString ="select * from tname";// where wbcss = "+id2
//+" AND headname = " +"'" +name2+"'"+ " AND headvalue = " +"'"+value2+"'";
ResultSet rst = stmt.executeQuery(sqlLanguageString);
while(rst.next())
{
int outputId = rst.getInt("wbcssid");
Integer outputIdInteger = new Integer(outputId);
String outputIdString = outputIdInteger.toString();
String outputHead = rst.getString("headname");
String outputValue = rst.getString("headvalue");
String checkValue = "record" + outputIdString;
out.println("<p><input type=checkbox name='recordcheck' value="+outputIdString+">"
+"<a href='save.jsp'>"+outputId+outputHead+outputValue);
out.println("<br>");
}
}
catch(ClassNotFoundException e)
{
System.out.print("ClassNotFoundException occur when connect to database!");
}
catch(SQLException e)
{
System.out.print("SQLException occur when output data!");
}
out.print("<br>"
+"<input type='submit' name='delete' value='删除'>"
+"</form>");
out.print("<form method='post' action='addrelog.jsp'>"
+"<input type='submit' name='addnew' value='新增'>"
+"</form>");
}
out.println("id1=="+idString) ;
for(int i=0;i<idString.length();i++)
{
if(((char)idString.charAt(i)>'9')||((char)idString.charAt(i)<'0'))
{
islegal = false;
break;
}
}
if(islegal)
{
idInteger = java.lang.Integer.valueOf(idString);
id2 = idInteger.intValue();
out.println("id2=="+id2) ;
name2 = request.getParameter("name1");
value2 = request.getParameter("value1");
}
%>
用上面的代码跟踪一下。
out.println("id1=="+idString) ;//***
for(int i=0;i<idString.length();i++)
{
if(((char)idString.charAt(i)>'9')||((char)idString.charAt(i)<'0'))
{
islegal = false;
break;
}
}
out.print(islegal);////*******
输出id是数字,islegal is false???
这里输出的是什么?
islegal=true;//*******I see.But Why must set true here???
for(int i=0;i<idString.length();i++)
{
if(((char)idString.charAt(i)>'9')||((char)idString.charAt(i)<'0'))
{
islegal = false;
break;
如果不是,出现提示错误信息,且不能提交,这样在update中就不
要判断了,其实是不提昌在下过页面进行判断的。
下面提供js函数。//检测是否是整数
function isInteger(inputVal) {
var iNumber;
if (inputVal.length > 0) {
iNumber = Number(inputVal);
if (isNaN(iNumber))
return false;
else if (String(iNumber).indexOf(".") >= 0)
return false;
}
return true;
}
你在update.jsp中可这样来接收id1的数据。
int id1 = Integer.parseInt(request.getParameter("id1").equals("")?"0":request.getParameter("id1")) ;这样你就不用判断了,直接组合sql进行查询。
试试吧。