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

推荐订阅源

Recent Announcements
Recent Announcements
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
腾讯CDC
D
Docker
G
Google Developers Blog
D
DataBreaches.Net
雷峰网
雷峰网
Blog — PlanetScale
Blog — PlanetScale
S
SegmentFault 最新的问题
The Cloudflare Blog
有赞技术团队
有赞技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Stack Overflow Blog
Stack Overflow Blog
大猫的无限游戏
大猫的无限游戏
量子位
美团技术团队
aimingoo的专栏
aimingoo的专栏
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Engineering at Meta
Engineering at Meta
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - 岌岌可危

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