当前位置:网站首页>Record: solution of 404 error of servlet accessing database in dynamic web project
Record: solution of 404 error of servlet accessing database in dynamic web project
2022-07-06 13:00:00 【Non wind thought】
dynamic Web project servlet Access database 404 Error resolution
login.html
stay login.html Enter the user's password and click login on the page displayed in the browser , according to action/Web/login go to Web Under the project web.xml file .
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<form action="/Web/login" method="post">
user name :<input type="text" name="username"><br>
password :<input type="password" name="password"><br>
<input type="submit" value=" Sign in "><br>
</form>
</body>
</html>
web.xml
stay xml In the document servlet-mapping In the tag url-pattern In the tag /login, find /login after , According to the above servlet-name Text in label LoginServlet Look for servlet In the label servlet-name The same text in the label LoginServlet, Then find the following servlet-class The text in the label login.LoginServlet, This text indicates to run .java The path of the file ( The bag where it is ).
<servlet>
<description></description>
<display-name>LoginServlet</display-name>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>login.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
LoginServlet.java
according to xml In the path ( The bag where it is ) To run the LoginServlet.java file , So as to operate the data in the database
package login;
import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;
import domain.User;
import utils.DataSourceUtils;
public class LoginServlet extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//1. Get user name and password
String username = request.getParameter("username");
String password = request.getParameter("password");
//2. Verify whether the user name and password are missing from the database
QueryRunner runner = new QueryRunner(DataSourceUtils.getDataSource());
String sql = "select * from user where username=? and password=?";
User user = null;
try {
user = runner.query(sql, new BeanHandler<User>(User.class), username,password);
} catch (SQLException e) {
// TODO Automatically generated catch block
e.printStackTrace();
}
//3. Different display information is given to users according to the returned results
if (user!=null) {
// User login successful
response.getWriter().write(user.toString());
}else {
// User login failed
response.getWriter().write("sorry your username or password is wriong!!!");
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doGet(request, response);
}
}
therefore web.xml Medium url-mapping Text /login Medium login Must be with form Labeled action=/Web/login Medium login The same name
边栏推荐
- [Chongqing Guangdong education] Shandong University College Physics reference materials
- Excel导入,导出功能实现
- 错误:排序与角标越界
- FairyGUI增益BUFF數值改變的顯示
- [算法] 剑指offer2 golang 面试题10:和为k的子数组
- GNSS positioning accuracy index calculation
- C code implementation of robust estimation in rtklib's pntpos function (standard single point positioning spp)
- Sharing ideas of on-chip transplantation based on rtklib source code
- Shortest Hamilton path (pressure DP)
- Mysql database reports an error: row size too large (> 8126) Changing some columns to TEXT or BLOB or using ROW_ FORMAT=DY
猜你喜欢

服务未正常关闭导致端口被占用
![[Chongqing Guangdong education] Shandong University College Physics reference materials](/img/56/4ac44729c3e480a4f779d6a890363a.jpg)
[Chongqing Guangdong education] Shandong University College Physics reference materials

PR 2021 quick start tutorial, first understanding the Premiere Pro working interface
![[算法] 剑指offer2 golang 面试题8:和大于或等于k的最短子数组](/img/8c/1b6ba3b1830ad28176190170c98628.png)
[算法] 剑指offer2 golang 面试题8:和大于或等于k的最短子数组
![[dry goods] cycle slip detection of suggestions to improve the fixed rate of RTK ambiguity](/img/9d/7284c1399964d3fb48886f12e4941c.jpg)
[dry goods] cycle slip detection of suggestions to improve the fixed rate of RTK ambiguity

FairyGUI簡單背包的制作

Detailed explanation of balanced binary tree is easy to understand

Idea problem record

FairyGUI摇杆

Halcon knowledge: gray_ Tophat transform and bottom cap transform
随机推荐
Chromatic judgement bipartite graph
Force buckle 1189 Maximum number of "balloons"
[algorithm] sword finger offer2 golang interview question 12: the sum of the left and right sub arrays is equal
[algorithm] sword finger offer2 golang interview question 7: 3 numbers with 0 in the array
Mixed use of fairygui button dynamics
The port is occupied because the service is not shut down normally
Fairygui character status Popup
[Chongqing Guangdong education] reference materials for regional analysis and planning of Pingdingshan University
【RTKLIB 2.4.3 b34 】版本更新简介一
[算法] 剑指offer2 golang 面试题8:和大于或等于k的最短子数组
VLSM variable length subnet mask partition tips
GPS高程拟合抗差中误差的求取代码实现
[算法] 剑指offer2 golang 面试题13:二维子矩阵的数字之和
Fundamentals of UD decomposition of KF UD decomposition [1]
The service robots that have been hyped by capital and the Winter Olympics are not just a flash in the pan
(core focus of software engineering review) Chapter V detailed design exercises
Employment of cashier [differential constraint]
Devops' future: six trends in 2022 and beyond
Affichage du changement de valeur du Buff de gain de l'interface graphique de défaillance
[算法] 剑指offer2 golang 面试题1:整数除法