请求的资源 [projectname/servlet] 不可用
The requested resource [projectname/servlet] is not available
这是我的项目结构:-
[1]: https://i.stack.imgur.com/ootY1.png
我的问题是每当我 运行 我在服务器上的项目时,都会出现 HTTP 状态 404 错误。
这是我从服务器收到的错误:-
The requested resource [/Doctor_Appointment_Application/Regis] is not available
我正在使用注释来注册我的 servlet,但我的 web.xml.
中只有一个欢迎文件
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="4.0"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd">
<display-name>User Login</display-name>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>/JSP/login.jsp</welcome-file>
</welcome-file-list>
</web-app>
我的注册 Servlet:-
package com.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.bean.RegisBean;
import com.dao.RegisDao;
@WebServlet("/Regis")
public class Regis extends HttpServlet {
private static final long serialVersionUID = 1L;
public Regis() {
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String fullname=request.getParameter("fullname");
String email=request.getParameter("email");
String username=request.getParameter("username");
String password=request.getParameter("password");
long mobile= Long.parseLong(request.getParameter("mobile"));
String address=request.getParameter("address");
String identity=request.getParameter("radio");
String specialisation=request.getParameter("special");
String degree=request.getParameter("degree");
String exp=request.getParameter("exp");
String fees=request.getParameter("fees");
RegisBean regisBean=new RegisBean();
regisBean.setFullname(fullname);
regisBean.setEmail(email);
regisBean.setUsername(username);
regisBean.setPassword(password);
regisBean.setMobile(mobile);
regisBean.setAddress(address);
regisBean.setIdentity(identity);
if(identity.equals("Doctor")) {
regisBean.setSpecialiasation(specialisation);
regisBean.setDegree(degree);
regisBean.setExperience(exp);
regisBean.setFees(fees);
}
RegisDao dao=new RegisDao();
String userRegistered=dao.registerUser(regisBean);
if(userRegistered.equals("SUCCESS"))
request.getRequestDispatcher("/JSP/conf.jsp").forward(request, response);
else {
request.setAttribute("errMessage", userRegistered);
request.getRequestDispatcher("/JSP/register.jsp").forward(request, response);
}
}
}
编辑 1:
Register.jsp:-
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Registration Page</title>
<style type="text/css">
<%-- <%@include file="/CSS/register.css"%> --%>
<%@include file="/CSS/regis.css"%>
</style>
<script src='https://kit.fontawesome.com/a076d05399.js'></script>
<script>
function validate() {
var password = document.form.password.value;
var confpassword = document.form.confpassword.value;
/* if (password.length < 6) {
alert("Password must be at least 6 characters long.");
return false;
} else */ if (password != confpassword) {
alert("Confirm Password should match with the Password");
return false;
}
}
</script>
</head>
<body>
<form name="form" action="<%=request.getContextPath() %>/Regis" method="post" onsubmit="return validate()">
Full Name: <input type="text" name="fullname" required>
<br>
<br>
Email: <input type="text" name="email" required>
<br>
<br>
Username: <input type="text" name="username" required>
<br>
<br>
Password: <input type="password" name="password" required>
<br>
<br>
Confirm Password: <input type="password" name="confpassword" required>
<br>
<br>
Mobile Number: <input type="number" name="mobile" required>
<br>
<br>
Address: <input type="text" name="address" required>
<br>
<br>
Identity: Doctor <input type="radio" name="radio" value="Doctor" required>
<div class="reveal">
Specialisation: <select name="special" class="require-if-active">
<option selected disabled>Choose...</option>
<option value="Allergist">Allergist</option>
<option value="Anesthesiologist">Anesthesiologist</option>
<option value="Cardiologist">Cardiologist</option>
<option value="Dermatologist">Dermatologist</option>
<option value="Endocrinologist">Endocrinologist</option>
<option value="Gastroenterologist">Gastroenterologist</option>
<option value="Hematologist">Hematologist</option>
<option value="Immunologist">Immunologist</option>
<option value="Internist">Internist</option>
<option value="Neurologist">Neurologist</option>
<option value="Pulmonologist">Pulmonologist</option>
<option value="Oncologist">Oncologist</option>
</select>
<br>
<br>
Degree: <select name="degree" class="require-if-active">
<option selected disabled>Choose...</option>
<option value="MBBS">MBBS</option>
<option value="BDS">BDS</option>
<option value="BAMS">BAMS</option>
<option value="BUMS">BUMS</option>
<option value="BHMS">BHMS</option>
<option value="BYNS">BYNS</option>
<option value="B.V.Sc & AH">B.V.Sc & AH</option>
</select>
<br>
<br>
Experience: <input type="number" name="exp" class="require-if-active">
<br>
<br>
Fees: <input type="number" name="fees" class="require-if-active">
</div>
Patient <input type="radio" name="radio" value="Patient" required>
<span style="color: red"><%=(request.getAttribute("errMessage") == null) ? "" : request.getAttribute("errMessage")%></span>
<br>
<br> <input type="submit" value="Register">
</form>
</body>
</html>
编辑 2:
我只是想做一个实验,我所做的是创建另一个 jsp 文件和一个 servlet 来检查问题是否出在我的 jsp 和 servlet 文件中。所以同样的事情发生了,jsp 文件 运行 成功但是服务器在提交表单方法后无法找到 servlet。
感谢任何形式的帮助。
更新(基于问题中发布的更新):
替换
<form name="form" action="<%=request.getContextPath() %>/Regis" method="post" onsubmit="return validate()">
和
<form name="form" action="Regis" method="post" onsubmit="return validate()">
因为 JSP 中的路径已经相对于上下文路径。
原回答:
您收到此错误的原因是默认情况下,服务器将请求作为 GET
而您没有在您的 servlet 中提供 doGet
的任何实现。如果您从 JSP/HTML 调用此 servlet,请务必提及 method="POST"
。如果您尝试直接调用 servlet,您可以将 doPost
重命名为 doGet
或提供 doGet
的实现,例如
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
看到这个的人你好,
我通过从我的构建路径中删除 mysqljdbc.auth.dll 解决了这个查询。这解决了我的问题,现在工作正常。如果您对 mysqljdbc.auth.dll 文件有问题,只需将其复制到 JDK 8 bin 文件夹中,它就可以正常工作。
这是我的项目结构:- [1]: https://i.stack.imgur.com/ootY1.png
我的问题是每当我 运行 我在服务器上的项目时,都会出现 HTTP 状态 404 错误。 这是我从服务器收到的错误:-
The requested resource [/Doctor_Appointment_Application/Regis] is not available
我正在使用注释来注册我的 servlet,但我的 web.xml.
中只有一个欢迎文件Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="4.0"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd">
<display-name>User Login</display-name>
<session-config>
<session-timeout>30</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>/JSP/login.jsp</welcome-file>
</welcome-file-list>
</web-app>
我的注册 Servlet:-
package com.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.bean.RegisBean;
import com.dao.RegisDao;
@WebServlet("/Regis")
public class Regis extends HttpServlet {
private static final long serialVersionUID = 1L;
public Regis() {
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String fullname=request.getParameter("fullname");
String email=request.getParameter("email");
String username=request.getParameter("username");
String password=request.getParameter("password");
long mobile= Long.parseLong(request.getParameter("mobile"));
String address=request.getParameter("address");
String identity=request.getParameter("radio");
String specialisation=request.getParameter("special");
String degree=request.getParameter("degree");
String exp=request.getParameter("exp");
String fees=request.getParameter("fees");
RegisBean regisBean=new RegisBean();
regisBean.setFullname(fullname);
regisBean.setEmail(email);
regisBean.setUsername(username);
regisBean.setPassword(password);
regisBean.setMobile(mobile);
regisBean.setAddress(address);
regisBean.setIdentity(identity);
if(identity.equals("Doctor")) {
regisBean.setSpecialiasation(specialisation);
regisBean.setDegree(degree);
regisBean.setExperience(exp);
regisBean.setFees(fees);
}
RegisDao dao=new RegisDao();
String userRegistered=dao.registerUser(regisBean);
if(userRegistered.equals("SUCCESS"))
request.getRequestDispatcher("/JSP/conf.jsp").forward(request, response);
else {
request.setAttribute("errMessage", userRegistered);
request.getRequestDispatcher("/JSP/register.jsp").forward(request, response);
}
}
}
编辑 1:
Register.jsp:-
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Registration Page</title>
<style type="text/css">
<%-- <%@include file="/CSS/register.css"%> --%>
<%@include file="/CSS/regis.css"%>
</style>
<script src='https://kit.fontawesome.com/a076d05399.js'></script>
<script>
function validate() {
var password = document.form.password.value;
var confpassword = document.form.confpassword.value;
/* if (password.length < 6) {
alert("Password must be at least 6 characters long.");
return false;
} else */ if (password != confpassword) {
alert("Confirm Password should match with the Password");
return false;
}
}
</script>
</head>
<body>
<form name="form" action="<%=request.getContextPath() %>/Regis" method="post" onsubmit="return validate()">
Full Name: <input type="text" name="fullname" required>
<br>
<br>
Email: <input type="text" name="email" required>
<br>
<br>
Username: <input type="text" name="username" required>
<br>
<br>
Password: <input type="password" name="password" required>
<br>
<br>
Confirm Password: <input type="password" name="confpassword" required>
<br>
<br>
Mobile Number: <input type="number" name="mobile" required>
<br>
<br>
Address: <input type="text" name="address" required>
<br>
<br>
Identity: Doctor <input type="radio" name="radio" value="Doctor" required>
<div class="reveal">
Specialisation: <select name="special" class="require-if-active">
<option selected disabled>Choose...</option>
<option value="Allergist">Allergist</option>
<option value="Anesthesiologist">Anesthesiologist</option>
<option value="Cardiologist">Cardiologist</option>
<option value="Dermatologist">Dermatologist</option>
<option value="Endocrinologist">Endocrinologist</option>
<option value="Gastroenterologist">Gastroenterologist</option>
<option value="Hematologist">Hematologist</option>
<option value="Immunologist">Immunologist</option>
<option value="Internist">Internist</option>
<option value="Neurologist">Neurologist</option>
<option value="Pulmonologist">Pulmonologist</option>
<option value="Oncologist">Oncologist</option>
</select>
<br>
<br>
Degree: <select name="degree" class="require-if-active">
<option selected disabled>Choose...</option>
<option value="MBBS">MBBS</option>
<option value="BDS">BDS</option>
<option value="BAMS">BAMS</option>
<option value="BUMS">BUMS</option>
<option value="BHMS">BHMS</option>
<option value="BYNS">BYNS</option>
<option value="B.V.Sc & AH">B.V.Sc & AH</option>
</select>
<br>
<br>
Experience: <input type="number" name="exp" class="require-if-active">
<br>
<br>
Fees: <input type="number" name="fees" class="require-if-active">
</div>
Patient <input type="radio" name="radio" value="Patient" required>
<span style="color: red"><%=(request.getAttribute("errMessage") == null) ? "" : request.getAttribute("errMessage")%></span>
<br>
<br> <input type="submit" value="Register">
</form>
</body>
</html>
编辑 2:
我只是想做一个实验,我所做的是创建另一个 jsp 文件和一个 servlet 来检查问题是否出在我的 jsp 和 servlet 文件中。所以同样的事情发生了,jsp 文件 运行 成功但是服务器在提交表单方法后无法找到 servlet。
感谢任何形式的帮助。
更新(基于问题中发布的更新):
替换
<form name="form" action="<%=request.getContextPath() %>/Regis" method="post" onsubmit="return validate()">
和
<form name="form" action="Regis" method="post" onsubmit="return validate()">
因为 JSP 中的路径已经相对于上下文路径。
原回答:
您收到此错误的原因是默认情况下,服务器将请求作为 GET
而您没有在您的 servlet 中提供 doGet
的任何实现。如果您从 JSP/HTML 调用此 servlet,请务必提及 method="POST"
。如果您尝试直接调用 servlet,您可以将 doPost
重命名为 doGet
或提供 doGet
的实现,例如
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
看到这个的人你好, 我通过从我的构建路径中删除 mysqljdbc.auth.dll 解决了这个查询。这解决了我的问题,现在工作正常。如果您对 mysqljdbc.auth.dll 文件有问题,只需将其复制到 JDK 8 bin 文件夹中,它就可以正常工作。