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

推荐订阅源

S
Security Affairs
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Jina AI
Jina AI
P
Palo Alto Networks Blog
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
A
Arctic Wolf
Hugging Face - Blog
Hugging Face - Blog
小众软件
小众软件
Y
Y Combinator Blog
T
The Blog of Author Tim Ferriss
Blog — PlanetScale
Blog — PlanetScale
S
Schneier on Security
V
Vulnerabilities – Threatpost
C
Cybersecurity and Infrastructure Security Agency CISA
雷峰网
雷峰网
T
Tenable Blog
人人都是产品经理
人人都是产品经理
T
Tor Project blog
C
Cyber Attacks, Cyber Crime and Cyber Security
AWS News Blog
AWS News Blog
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
Scott Helme
Scott Helme
SecWiki News
SecWiki News
C
CERT Recently Published Vulnerability Notes
Recorded Future
Recorded Future
I
InfoQ
Security Archives - TechRepublic
Security Archives - TechRepublic
Help Net Security
Help Net Security
Cloudbric
Cloudbric
C
Check Point Blog
Engineering at Meta
Engineering at Meta
TaoSecurity Blog
TaoSecurity Blog
B
Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园_首页
N
News and Events Feed by Topic
云风的 BLOG
云风的 BLOG
MyScale Blog
MyScale Blog
腾讯CDC
量子位
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
Kaspersky official blog
Vercel News
Vercel News
F
Full Disclosure
T
Troy Hunt's Blog
Forbes - Security
Forbes - Security
S
Security @ Cisco Blogs

博客园 - 岌岌可危

免费的打印管理软件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