javascript - 如何在 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>
解决方案
推荐阅读
- python - 列表和迭代器之间的可能差异
- regex - 正则表达式从 10000 到 1800000
- c# - ffmpeg 音频质量差(仅)?如何配置
- javascript - 测验中正确回答的平均问题数
- angular - 在 2 个输入字段中显示拆分并显示字符串值
- python - 如何检索单个 7zip 文件而不在 Python3.x 中提取所有文件?
- java - 有没有更好的方法来检查 HttpServletRequest.getParamter() 中的 null
- javascript - 未捕获的 DOMException:无法在 'Node' 上执行 'appendChild':新的子元素包含父元素
- android - 是否可以在 retrofit2 中发送带有 multipart 的 @Fields?
- docker - 如果应用程序初始化失败,如何阻止 docker 容器启动?