在JSP界面写了修改密码的操作,点击修改密码,无法跳到修改密码的界面,萌新求大佬教一下。谢谢!!

这是jsp界面的代码

<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="java.sql.*" %>
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@ page import="controller.*" %>
<%@ page import= "utils.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path;
String applicationPath = basePath + "/" + "application";
%>
<jsp:useBean id="a" scope="page" class="utils.DbUtils"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312";>
<title>
change
</title>
</head>
<body bgcolor="#ffffff">


   <%
   String pwd="";
   int uid = (Integer)session.getAttribute("uid");

   String sql="";
     sql="SELECT * FROM users where id="+uid;
     ResultSet rs = a.executeQuery(sql);
     if(rs.next()){
       pwd=rs.getString("PASSW");
     }
   %>

<SCRIPT LANGUAGE="javascript" >
 function checkform(){
         if(form2.pwd1.value!="<%=pwd%>"||form2.pwd1.value=="")
         {
                alert("输入的原始密码不正确,请重新输入");
                form2.pwd1.focus();
                return false;
         }
           if(form2.pwd2.value=="")
           {
                   alert("请输入新密码");
                   form2.pwd2.focus();
                 return false;
                  }


            else if(form2.pwd2.value!=form2.pwd3.value)
              {
                 alert("两次输入的新密码不同,请重新输入");
                 form2.pwd3.focus();
                 return false;
              }
             else
            {
              alert("密码修改成功");
              return true;
            }
            return true;
 }
</SCRIPT>

 <link rel="stylesheet" type="text/css" media="all" href="<%=path%>/images/css1/ioa.css" />

 <center>
 <form action="update_pwd.jsp" method="POST" name="form2">

<table width="100%" border="0" cellspacing="0" cellpadding="0" class="pad5">
  <tr>
    <td valign="top" align="left" class="pad5">
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="dqbg margb5">
          <tr>
            <td width="2%" align="right" class="pad05"><img src="<%=path%>/images/img2.gif" width="16" height="16"></td>
            <td width="98%" align="left" class="lan13b">密码修改</td>
          </tr>
        </table>
        <table width="100%" border="0" cellpadding="1" cellspacing="1" class="table-border margb5">

                   <tr>

            <td width="14%" align="right" class="COLLECTION">请输入原密码:</td>
            <td width="36%" align="left" class="even padl5">        <input  type=password name="pwd1"  maxlength="32"
                    onfocus="WdatePicker({readOnly:true})" /> </td>


          </tr>
           <tr>

            <td width="14%" align="right" class="COLLECTION">请输入新密码:</td>
            <td width="36%" align="left" class="even padl5"><input type=password name="pwd2"   maxlength="32" class="inputnormal" value=""></td>
          </tr>

                   <tr>

            <td width="14%" align="right" class="COLLECTION">确认新密码:</td>
            <td width="36%" align="left" class="even padl5"><input type=password name="pwd3"   maxlength="32" class="inputnormal" value=""></td>
          </tr>
      </table>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td width="50%" align="right" class="padr5"><input type="submit" onclick="javascript:return(checkform());" name="button" value="保 存" class="button"></td>
            <td width="50%" align="left" class="padl5"><input name="button1" type="button" class="button" onClick="history.go(-1);" value="返 回"></td>
          </tr>
        </table>
    </td>
  </tr>
</table>
  </form>
 </center>
</body>
</html>


下面的错误提示:
type Exception report

message An exception occurred processing JSP page /pwd.jsp at line 25

description The server encountered an internal error that prevented it from fulfilling this request.

exception
org.apache.jasper.JasperException: An exception occurred processing JSP page /pwd.jsp at line 25

22: 
23:    <%
24:    String pwd="";
25:    int uid = (Integer)session.getAttribute("uid");
26:   
27:    String sql="";
28:      sql="SELECT * FROM users where id="+uid;


Stacktrace:
    org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:579)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:476)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


root cause
java.lang.NullPointerException
    org.apache.jsp.pwd_jsp._jspService(pwd_jsp.java:150)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:396)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:340)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)


note The full stack trace of the root cause is available in the Apache Tomcat/8.0.39 logs.

2个回答

 int uid = (Integer)session.getAttribute("uid");

这段代码需要判空操作,如果后台没有设置 uid 属性,这里就是空指针。检测下后台代码,并加固一下这里的代码。

qq_36734182
qq_36734182 那请问怎么在后台设置uid的属性呢?怎么加固这里的代码呢,
4 个月之前 回复

先判断一下session中这个uid是否存在,存在再获取,不存在的时候你直接强转也没用。

还有就是要学着看报错信息:
An exception occurred processing JSP page /pwd.jsp at line 25
运行时出现异常在jsp页面pwd.jsp文件的第25行

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问