第一次存盘编译时都没问题,无论输入数字还是字符
问题是输入字符后,提交opr.jsp处理,提示非法字符(说明判断无误)
回到login.jsp再输入数字,提交opr.jsp处理仍然提示非法字符

解决方案 »

  1.   

    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>
      

  2.   


    <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呢?
      

  3.   

    我是想在第二个页面updata.jsp验证输入ID是否数字,否则回到log.jsp
    现在是输入一次非字符后,回到log.jsp再输入数字仍按非字符处理
    第一次就输入数字就正确
      

  4.   

    还是不行,怪哉!而且地址中传递的是正确参数
    http://localhost:8080/system/updata.jsp?id1=46&name1=fgh&value1=fgj
    为什么按照错误的id1处理呢?
      

  5.   

    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>");
        }
      

  6.   

    <%  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");
        }
    %>
    用上面的代码跟踪一下。
      

  7.   

    <%  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???
      

  8.   

    out.println("id1=="+idString) ;//***
    这里输出的是什么?
      

  9.   

    <%  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;
      

  10.   

    你最是在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进行查询。
    试试吧。