惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

W
WeLiveSecurity
T
Tenable Blog
Project Zero
Project Zero
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
S
Schneier on Security
Scott Helme
Scott Helme
S
Securelist
Know Your Adversary
Know Your Adversary
Vercel News
Vercel News
IT之家
IT之家
V
V2EX
F
Fortinet All Blogs
Simon Willison's Weblog
Simon Willison's Weblog
K
Kaspersky official blog
博客园_首页
T
Tailwind CSS Blog
The GitHub Blog
The GitHub Blog
Spread Privacy
Spread Privacy
Microsoft Security Blog
Microsoft Security Blog
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
有赞技术团队
有赞技术团队
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
Cyberwarzone
Cyberwarzone
Google DeepMind News
Google DeepMind News
The Hacker News
The Hacker News
L
LINUX DO - 热门话题
Hugging Face - Blog
Hugging Face - Blog
博客园 - 三生石上(FineUI控件)
A
Arctic Wolf
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
C
CXSECURITY Database RSS Feed - CXSecurity.com
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Threat Research - Cisco Blogs
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
D
Darknet – Hacking Tools, Hacker News & Cyber Security
C
CERT Recently Published Vulnerability Notes
S
SegmentFault 最新的问题
AWS News Blog
AWS News Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
罗磊的独立博客
Apple Machine Learning Research
Apple Machine Learning Research
P
Proofpoint News Feed
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
Vulnerabilities – Threatpost

博客园 - 岌岌可危

免费的打印管理软件easyjen 书籍链接 CrowdStrike引起的一次失败又成功的故障恢复 简单四则运算器 作业之打印金字塔 方差计算,使用类和常规方式 python作业 如何在Windows Server 2016上重置用户“管理员”的密码 huey在windows下使用的坑 sublimeCodeIntel在windows下安装的坑 python pip安装失败 如何创建和编译动态链接库并且在另一应用程序中调用它。 Visual Studio2019 cannot open source Django创建模型。 Django创建视图 Django创建项目和应用 无Admin权限安装python 嵌入版本和PIP,并安装Django python,Django安装在windows上 一段代码实现RPC DCOM和RPC,两者的认证过程有什么区别?
简单java servlet的登录脚本,部署到docker
岌岌可危 · 2023-01-06 · via 博客园 - 岌岌可危

先打算参考这篇文章

Simple login page example using jsp servlet - Candidjava

内含war文件和zip文件。但是tomcat上该war文件总是报错。

于是又参考这篇

(46条消息) Java学习day3——Javaweb登录页面设计(1)(含JSP代码)_苏三有春的博客-CSDN博客_web登录界面设计代码

复制代码,略加修改,没有使用war,使用纯JSP.

 写了3个jsp

 loginSuccess.jsp
<%@ page language="java" contentType="text/html; charset=UTF=8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>loginSuccess</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");//解决提交方式post时,中文乱码问题
String userName = null;
String userPwd = null;
if(request.getParameter("userName")!=null){
userName=request.getParameter("userName");
userPwd = request.getParameter("password");
}
if(userName.equals("admin")&&userPwd.equals("123")){
//当用户名和密码正确时
request.setAttribute("mess", "登陆成功");
session.setAttribute("userName", userName);
session.setAttribute("userPwd",userPwd);
//进入content.jsp页面
response.sendRedirect("content.jsp");
}else{
//当用户名或密码不正确时
request.setAttribute("mess", "用户名或密码错误");
request.getRequestDispatcher("index.jsp").forward(request, respo
nse);
}
%>
<h3>userName:<%= userName %></h3>
<h3>password:<%= request.getParameter("password") %></h3>
</body>
</html>

index.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录页面</title>
</head>
<body>
<%
String mess = null;
if(request.getAttribute("mess")!=null){
mess = (String)request.getAttribute("mess");
}
%>
<h3>input admin and 123</h3>
<form method="post" action="loginSuccess.jsp">
<label>用户名:</label>
<input type="text" name="userName" ><br>
<label>密码:</label>
<input type="password" name="password" ><br>
<input type="submit" value="登录" >
<p sytle="color: red"><%= mess != null ? mess : "" %></p>
</form>

</body>
</html>

content.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Index page, login success</title>
</head>
<body>
<%
String userName = (String)session.getAttribute("userName");
String userPwd = (String)session.getAttribute("userPwd");
session.setMaxInactiveInterval(3*60);//设置session失效时间
%>
<h1>恭喜你登录成功</h1>
<h1>欢迎合法用户: <%= userName != null ? userName : ""%></h1>


<p>sessionId: <%= session.getId() %></p>

</body>
</html>

然后打包成xxx.tar.gz文件

再制作Dockerfile


FROM tomcat

LABEL maintainer="admin@soft.com"

ADD root.tar.gz /usr/local/tomcat/webapps/

EXPOSE 8080

CMD ["/usr/local/tomcat/bin/catalina.sh", "run"]

再参考Deploying Your First Web App to Tomcat on Docker | Cprime

制作和运行docker