首页 > 解决方案 > 如何在 home.jsp 页面右侧显示 Z ID 以欢迎用户或欢迎 Z ID

问题描述

我试图在 home.jsp 页面的右上角显示相应的用户“Z ID”。我已经使用 EL 概念对我的代码进行了一些修改,但对我来说它不起作用。当用户登录时,它会重定向到 home.jsp 页面,在 home.jsp 页面上我想显示用户的 Z ID。我做错了什么?

这是我的 Home.jsp 页面

<%@page contentType="text/html" pageEncoding="UTF-8"%>
  <!DOCTYPE html>
  <html>

  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Home Page</title>
    <style>
      h1 {
        text-shadow: 2px 2px 5px red;
      }
      
      .container {
        width: 90%;
        padding: 20px;
        margin: 100px auto;
        background: #ddd;
        display: flex;
        flex-direction: row;
        justify-content: center;
        text-align: center;
        vertical-align: middle;
        line-height: 250px;
      }
      
      .box {
        width: 250px;
        height: 300px;
        background: #2495ff;
        margin: 0px 10px;
        transition: 1s;
        text-decoration: none;
      }
      
      .box:hover {
        transform: scale(1.3);
        background: #2495ff;
        z-index: 2;
        box-shadow: 2px 2px 2px #000;
        text-decoration: none;
      }
      
      body {
        background-color: lightblue;
      }
    </style>
  </head>

  <body>
    <br>
    <center>
      <h1>Welcome to Document Management System...</h1>
    </center>
    <br>

    <%
            
        String zid = request.getParameter("zid");
        if(zid != null){
            HttpSession sess = request.getSession();
            sess.setAttribute("zid",zid);
        }
            
        %>
      <div id="top">
        Hello ${zid.zid}
      </div>


      <div class="container">
        <div class="box"><b>New Document Upload</b></div>
        <div class="box"><b>View All Files</a></b></div>
        <div class="box"><b>Search or Extract Document</b></div>
        <div class="box"><b>Edit Profile</b></div>

      </div>
  </body>

  </html>

这是我的 login.jsp 页面

  <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>

    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>Login Page</title>
      <style>
        body {
          background-attachment: fixed;
        }
      </style>
    </head>

    <body>
      <form method="post" action="loginscriptJSP.jsp">
        <center>
          <table border="1" width="30%" cellpadding="3">
            <thead>
              <tr>
                <th colspan="2">Login Here</th>
              </tr>
            </thead>
            <tbody>
              <tr>
                <td>Z ID</td>
                <td><input type="text" name="zid" value="" /></td>
              </tr>
              <tr>
                <td>Password</td>
                <td><input type="password" name="pass" value="" /></td>
              </tr>
              <tr>
                <td><input type="submit" value="Login" /></td>
                <td><input type="reset" value="Reset" /></td>
              </tr>
              <tr>
                <td colspan="2">Yet Not Registered!! <a href="registrationJSP.jsp">Register Here</a></td>
              </tr>
            </tbody>
          </table>
        </center>
      </form>

    </body>

    </html>

这是我的 loginscriptJSP.jsp 页面

  <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>

    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
      <title>login script JSP Page</title>
    </head>

    <body>


      <%@ page import ="java.sql.*" %>
        <%
    String zfid = request.getParameter("zid");    
    String pwd = request.getParameter("pass");
    Class.forName("com.mysql.jdbc.Driver");
    Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/dmsqms",
            "root", "");
    Statement st = con.createStatement();
    ResultSet rs;
    rs = st.executeQuery("select * from dmsmembers where zid='" + zfid + "' and pass='" + pwd + "'");
    if (rs.next()) {
        session.setAttribute("zfid", zfid);
        //out.println("welcome " + userid);
        //out.println("<a href='logout.jsp'>Log out</a>");
        response.sendRedirect("home.jsp");
    } else {
        out.println("<script type=\"text/javascript\">");
        out.println("alert('Invalid username or password');");
        out.println("location='loginJSP.jsp';");
        out.println("</script>");
        
        
    }
%>





    </body>

    </html>

标签: javascripthtmljsp

解决方案


推荐阅读