我正在使用sendRedirect()
方法通过表单标签进行登录验证,因此我遇到了错误信息“ HTTP Status 404 –未找到”,描述为“ 原始服务器在Eclipse tomcat服务器8.5上找不到目标资源的当前表示形式,或不愿意透露它的存在。“,因为它在Mozilla浏览器上运行良好。无论是链接错误还是sendRedirect()方法导致该错误,我都有些困惑。这里是代码:
Web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1"> <display-name>ServletAppDemo</display-name> <welcome-file-list> <welcome-file>practice_form.html</welcome-file> <welcome-file>practice_form.htm</welcome-file> <welcome-file>practice_form.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>Login_SendRedirect</servlet-name> <servlet-class>sendRedirect2.VerifyLogin</servlet-class> </servlet> <servlet-mapping> <servlet-name>Login_SendRedirect</servlet-name> <url-pattern>/login</url-pattern> </servlet-mapping> <servlet> <servlet-name>VerifyUser</servlet-name> <servlet-class>sendRedirect2.verifiedUser</servlet-class> </servlet> <servlet-mapping> <servlet-name>VerifyUser</servlet-name> <url-pattern>/welcome_kid</url-pattern> </servlet-mapping> </web-app>
practice_form.html
<!DOCTYPE html> <html> <head> <meta charset="ISO-8859-1"> <title>Login</title> </head> <body> <form action="login" method="get"> User name :- <input type="text" name="uname"> <br><br> Password :- <input type="password" name="upass"> <br><br> <input type="submit" value="Submit"> </form> </body> </html>
VerifyLogin.java
package sendRedirect2; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class VerifyLogin extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/html"); PrintWriter pw = resp.getWriter(); String name = req.getParameter("uname"); String password = req.getParameter("upass"); if( name.equals("Prasad") && password.equals("password_x") ) { resp.sendRedirect("welcome_kid"); } else { pw.print("User name or password is incorrect"); RequestDispatcher dis = req.getRequestDispatcher("practice_form.html"); dis.include(req, resp); } pw.close(); } }
verifiedUser.java
] >>package sendRedirect2; import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class verifiedUser extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { resp.setContentType("text/html"); PrintWriter pw = resp.getWriter(); pw.println("Welcome to some website, "); } }
Mozilla浏览器中的输出:-
Eclipse Tomcat Server 8.5中的输出:-
请为此帮助我。
我正在使用sendRedirect()方法通过表单标签进行登录验证,因此遇到了错误信息“ HTTP Status 404 – Not Found”,描述为“源服务器未找到当前的...
我认为密码不正确。URL中提到了password_s。在程序中,您编写了password_x
[尝试检查。。我没有评论选项。因此必须将其作为答案。