qq_51978250 2021-10-19 00:35 采纳率: 0%
浏览 50

关于#JSP错误#的题目,请各位专家解答!

错误如下:

img

要求:
1.利用Request、session、Response等对象和Cookie操作实现未使用数据库的用户登录功能(用户名和密码为:“admin”和“admin”,或“iot”和“iot”),并统计显示该网站登录的人数。要求:

功能:
(1)用户登录页面:用户登录页面(如图1);
当用户选中复选框,表示需要通过Cookie技术将用户登录成功的账号及密码存储到客户端;
用户访问登录页面时,可以利用Cookie存储的内容实现免登录直接访问登录成功页面,否则显示登录表单内容要求用户输入账号和密码。

图1
(2)登录信息验证页面
如果用户名或密码为空则重新登陆(如图2);
如果用户名或密码错误则重新登陆(如图3);
如果登录成功,判定2秒后自动跳转到登陆成功页面,如果2秒后没跳转通过超链接点击进入登陆成功页面(如图4)。
(3)登录成功页面:
如果用户未登录访问本页面,提示“请登录后再访问”,2秒后页面跳转到用户登录页面,否则,显示欢迎文字及登陆该网站的总人数(如图5);
当点击登陆成功页面中的“注销”时,跳转到系统退出页面。
(4)系统退出页面:(如图6)。

①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="";
              Cookie [] cookies=request.getCookies();
              
              if(cookies!=null && cookies.length>0){
                  for(Cookie c:cookies){
                      if(c.getName().equals("name")){
                          
                          name=c.getValue();
                      }
                      if(c.getName().equals("pwd")){
                          pwd=c.getValue();
                      }
                  }
              %>
                  <jsp:forward page="login_check.jsp"></jsp:forward>
              <%    
                  
              }
           %>
        <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");
        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(true){
            if(name=="" || pwd==""){
    %>
        <%="<h4 align='center'>"+"用户名或密码为空!请重新"+"<a href='login.jsp'>"+"登录"+"</a>"+"系统!"+"</h4>"%>
    <%             
            }
            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>


③welcome.jsp:
<%@ page language="java" import="java.util.*" 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 'welcome.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">
    -->
    <%
        int i=0;
        if(application.getAttribute("num")==null)
            application.setAttribute("num","1");
        else{
             if(session.isNew()){
                String str=application.getAttribute("num").toString();  
                i=Integer.parseInt(str); 
                i++;
                application.setAttribute("num",i);
            }
        }


    %>
  </head>
  
  <body>
    <h2 align="center">登陆成功</h2>
    <h4 align="center">欢迎<%=session.getAttribute("name") %>光临本系统,您是第<%=application.getAttribute("num") %>位访客!
    <% request.setAttribute("name",session.getAttribute("name") ); %>
    <a href="over.jsp">注销</a></h4>
  </body>
</html>


④over.jsp:
<%@ page language="java" import="java.util.*" 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 'over.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>
          <% session.getAttribute("name");
              session.invalidate(); %>
        <h4 align="center">您已成功退出本系统,3秒后跳转回首页!</h4>
        <%
            response.setHeader("refresh", "3;URL=login.jsp");
        %>
        <h4 align="center">如果没有跳转,请按<a href="login.jsp">这里</a></h4>    
  </body>
</html>


  • 写回答

2条回答 默认 最新

  • CSDN专家-微编程 2021-10-19 09:20
    关注

    人家很明显给你指出来了login_check.jsp第47行开始报错,实际出错位置是46行,你这是html又不是Java代码,用什么<%= %>啊

    <%="<h4 align='center'>"+"用户名或密码为空!请重新"+"<a href='login.jsp'>"+"登录"+"</a>"+"系统!"+"</h4>"%>
    
    评论

报告相同问题?

问题事件

  • 创建了问题 10月19日

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料