qq_51978250 2021-10-19 16:00 采纳率: 0%
浏览 14

#JSP内置对象问题#错误

img


login.jsp


<%@ page language="java" import="java.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'login.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
  
  <body>
   <%!
              String name="";
              String pwd="";
              String flag="1";
      %>        
      <%
              Cookie [] cookies=request.getCookies();
              
              if(cookies!=null && cookies.length>0){
                  for(Cookie c:cookies){
                      if(c.getName().equals("name")){
                          name=c.getValue();
                      request.getRequestDispatcher("login_check.jsp").forward(request, response);    
                      }
                      if(c.getName().equals("pwd")){
                          pwd=c.getValue();
                      }
                      if(c.getName().equals("name")){
              
                      request.getRequestDispatcher("login_check.jsp").forward(request, response);    
                      }
                  }
                  
              }
           %>
        <table border="1" align="center">
        <form name="form1" action="login_check.jsp" method="post">
            <tr>
                <td align="center" colspan="2">用户登陆</td>
            </tr>
            <tr>
                <td>账号:</td>
                <td><input name="name" type="text" value="<%=name%>"></td>
            </tr>
            <tr>
                <td>密码:</td>
                <td><input name="pwd" type="password" value="<%=pwd%>"></td>
            </tr>
            <tr>
                <td>保存登录</td>
                <td><input type="checkbox" name="save" value="yes"></td>
            </tr>
            <tr>
                <td></td>
                <td><input type="submit" value="登陆">
                <input type="reset" value="重置"></td>
            </tr>
        </form>
    </table>
  
  </body>
</html>

login_check.jsp:

<%@ page language="java" import="java.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'login_check.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
      <h1 align="center">登陆操作</h1><hr>
  <body>

   <%
           
           
           String name=request.getParameter("name");
        String pwd=request.getParameter("pwd");
        System.out.print(name+"uh");
        String save=request.getParameter("save");
        String [][] tab={{"iot","iot"},{"admin","admin"}};
        if(save!=null&&save.equals("yes")){

            Cookie cookie1=new Cookie("name",name);
            Cookie cookie2=new Cookie("pwd",pwd);
            cookie1.setMaxAge(600*24);
            cookie2.setMaxAge(600*24);
            response.addCookie(cookie1);
            response.addCookie(cookie2);
        }
        
            if(name=="" || pwd==""){
    %>
        <h4 align="center">用户名或密码为空!请重新<a href="login.jsp">登录</a>系统!</h4>
    <%             
            }
            else{
                for(int i=0;i<tab.length;i++){
                      if(name.equals(tab[i][0])==true && pwd.equals(tab[i][1])==true){
                          session.setAttribute("name",name);
                          response.setHeader("refresh", "3;welcome.jsp");
                          out.print("<h4 align='center'>"+"用户登录成功,三秒后跳转到欢迎页面!"+"</h4>");
                        out.print("<h4 align='center'>"+"如果没有跳转,请点击"+"<a href='welcome.jsp'>"+"这里!"+"</a></h3>");
                        break;
                      }
                      else if(i==tab.length-1){        
                          out.println("<h4 align='center'>"+"用户名或密码出错!请重新"+"<a href='login.jsp'>"+"登录"+"</a>"+"系统!"+"</h3>");
                      }
                  } 
            }    
        
%>
              
      <%
        
        if(name==null){
            System.out.println("123");
            Cookie cookies[]=request.getCookies();
            for(int i=0;i<cookies.length;i++)
            {
                cookies[i].setMaxAge(0);
                response.addCookie(cookies[i]);
            }
            //response.sendRedirect("login.jsp");
        }
    
    
    
%>
     
  </body>
</html>


  • 写回答

1条回答 默认 最新

  • 小崔爱读书 2021-10-19 16:06
    关注

    你这个是空指针异常,具体哪行出现了空指针,真的不好说。你最好自己System.out.println打印一下。
    或者,你直接看一下 work 文件夹下的 login_check_jsp.java 文件 的 121 行吧,看看是啥代码。

    评论

报告相同问题?

问题事件

  • 创建了问题 10月19日

悬赏问题

  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元