声明:本人初学、自学jsp,请路过的同学看见这些“鸡毛蒜皮”级问题不要不屑于解答哈,我的成长有赖您的帮助!
写了一个登录页面及一个连接数据库查询数据的页面,详细代码如下:
<!--login.jsp-->
<%@ page language="java" %>
<%@ page import="java.io.*,java.util.*,java.sql.*,javax.sql.*,javax.naming.*"%>
<%@ page contentType="text/html;charset=GBK" %>
<%@ page errorPage="error.html" %>
<html>
<head>
<title>
aa系统
</title>
</head>
<body><style>
body{background:url("img\bodybg.gif");text-align:center;margin:30% auto;}
.div_style1{color:yellow;font-size:20px;}
</style><form>
<div class="div_style1">
<div>
请先登录
</div>
</br>
<div>
工号:<input type="text" name="id" size="19" maxlength="4">
</div>
<div>
密码:<input type="password" name="psw" size="20" maxlength="8">
</div>
</br>
<div>
<input type="submit" name="ok1" value="确定">
</div>
</div>
</form><%
String User_id="";
String User_psw="";
if(request.getParameter("ok1")!=null)
{
  User_id=request.getParameter("id");
  User_psw=request.getParameter("psw");
  if(User_id!=""&&User_psw!="")
 {
   try
  {
  Connection con;
  Statement stmt;
  ResultSet rs;
  Context ctx = new InitialContext();
  DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/db_set_free");
  con=ds.getConnection();
  stmt=con.createStatement();
  String sql="select * from tb_staff where staff_id=6911";
  rs=stmt.executeQuery(sql);s
  if (rs.next())
   {
     RequestDispatcher rd = request.getRequestDispatcher("nbr_set_free.jsp");
     rd.forward(request,response);
   }
   else
   {
     out.println("<p>您输入的id或密码错误,请重新输入...</p>");
   }
   rs.close();
   stmt.close();
   con.close();
  }
  catch(Exception e)
 {
  out.print(e.getMessage());
 }
 }
else
{
  out.println("<p>您输入的id或密码错误,请重新输入...</p>");
}
}
%></body>
</html><!--nbr_set_free.jsp-->
<%@ page language="java" %>
<%@ page import="java.io.*,java.util.*,java.sql.*,javax.sql.*,javax.naming.*"%>
<%@ page contentType="text/html;charset=GBK" %>
<%@ page errorPage="error.html" %>
<html>
<head>
<title>
work
</title>
</head>
<body><style type="text/css">
    body {background:url("img\bodybg.gif");
          text-align:center;
   margin:0 auto;
   padding:0;
   font:14px;}
    #div_top {
      float:none;
      width:800px;
      background:#efefef;
      font-size:93%;
      line-height:normal;
      border-bottom:1px solid #666;
      }
    #div_top ul {
  margin:0;
  padding:15px 0px 0 30px;
  list-style:none;
         align:center;
      }
    #div_top li {
      display:inline;
      margin:0;
      padding:0;
      }
    #div_top a {
      float:left;
      background:url("img/nav_left.gif") no-repeat left top;
      margin:0;
      padding:0 0 0 4px;
      text-decoration:none;
      }
    #div_top a span {
      float:none;
      display:block;
      background:url("img/nav_right.gif") no-repeat right top;
      padding:5px 12px 4px 6px;
      color:#FFF;
      }
    /* Commented Backslash Hack hides rule from IE5-Mac \*/
    #div_top a span {float:none;}
    /* End IE5-Mac hack */
    #div_top a:hover span {
      color:#FFF;
      }
    #div_top a:hover {
      background-position:0% -42px;
      }
    #div_top a:hover span {
      background-position:100% -42px;
      }    #div1 {
     margin:200,auto;
     float:none;
     height:20%;
     width:800px;
     background:#efefef;
     font-size:93%;
     line-height:normal;
     border-bottom:1px solid #666;
     }
     .div2{margin:20%,auto;}
</style><form>
<div id="div1">
<div id="div_top">
  <ul>
    <li><a href="http://www.pconline.com.cn/pcedu/" title="Link 1"><span>aa</span></a></li>
    <li><a href="http://www.pconline.com.cn/pcedu/" title="Link 2"><span>bb</span></a></li>
    <li><a href="http://www.pconline.com.cn/pcedu/" title="Link 3"><span>cc</span></a></li>
    <li><a href="http://132.111.76.224/set_free/reset_psw.jsp" title="Link 4"><span>修改密码</span></a></li>
  </ul>
</div>
<div class="div2">
<div>
清输入您要鱼肉的对象
</div>
</br>
</br>
<div>
<input type="text" name="nbr" size="19" maxlength="11">
</div>
</br>
<div>
<input type="submit" name="ok2" value="确定"><%
request.setCharacterEncoding("GBK");
String Input_nbr="";
if(request.getParameter("ok2")!=null)
{
  Input_nbr=request.getParameter("nbr");
 if(Input_nbr!="")
 {
   try
 {
   Connection con;
   Statement stmt;
   ResultSet rs;
   Context ctx = new InitialContext();
   DataSource ds=(DataSource)ctx.lookup("java:comp/env/jdbc/ibss1");
   con=ds.getConnection();
   stmt=con.createStatement();
   String sql_check="select * from tb_name where obj='aa'";
   ResultSet rs1=stmt.executeQuery(sql_check);
   if (rs1.next())
   { 
     String sql_update="update tb_name set name='bb'";
     stmt.executeUpdate(sql_update);
     out.println("<p>鱼肉成功。</p>");
   }
   else
   {
     out.println("<p>鱼肉不成功,请联系管理员处理。</p>");
   }
   rs1.close();
   stmt.close();
   con.close();
  }
  catch(Exception e)
{
  out.print(e.getMessage());
 } }
else
{
  out.println("<p>对象不存在,请重新输入...</p>");
}
}
%>
</div>
</div>
</div>
</form></body>
</html>问题:
1.两个页面按钮name值均为"ok"的话,过了登录页面login.jsp后,在nbr_set_free.jsp输入正确值后点按钮,页面回到login.jsp,并显示出错信息;
2.改了login.jsp的按钮name值为“ok1”,nbr_set_free.jsp的按钮name值为“ok2”后,正确登录跳转到nbr_set_free.jsp页面后,直接点按钮,页面又跳回login.jsp页面,并提示出错。
研究得出结论是:页面login.jsp在跳转后,他的按钮变量没有废掉?
怎么办?

解决方案 »

  1.   

    太恐怖了,建议楼主只贴出自己觉得问题所在的地方的代码,一是表示你自己思考过了,而是别人也没有那么的耐心看你那么长的code
      

  2.   

    噢,对不起,不好意思,也是太长了。
    问题是这样:有1、2两个页面,第一个是验证登录密码的,有一个登录按钮,属性“name”=“ok”,第二个页面是操作数据库的,也有一个按钮,假如属性“name”也设为“ok”的话,点击他就会返回到第一个页面。怎么办?
      

  3.   

    你可以在button里面用onclick =“js function()”
    js function(){
       document.form.action=“跳转的action或者页面”;
       document.form.submit;
    }
      

  4.   

    onClick="aa"<script language="javascript">
                   function aa(){
                     window.location.href="跳转的页面";
                   }
                   </script>