Ich versuche, ein Servlet aufzurufen, das je nach den Eingaben mich zu einem anderen JSP umleitet. Ich kann schon localhost nennen: 8080 und localhost: 8080/LoginApp/login.jsp, aber wenn ich den Absenden-Button klicken, sagt erAufruf von Servlet in JSP Formular
"HTTP-Status 404 - Not Found"
Typ Statusbericht
Nachricht/LoginApp/Login
Beschreibung der Ursprungs-Server, dass ein solches vorhanden ist, um nicht offen legen eine aktuelle Darstellung für die Zielressource finden oder nicht bereit ist.
Irgendwie kommt er nicht in die Post-Methode.
Ich habe eine einfache JSP-Datei login.jsp im WebContent Ordner
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login Page</title>
</head>
<body>
<form action="Login" method="POST">
<input type="text" name="userid"/>
<input type="password" name="password"/>
<input type="submit"/>
</form>
</body>
</html>
und die Servlet-Datei im Ordner src
@WebServlet(name = "Login", urlPatterns = {"/Login"})
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
public LoginServlet() {
super();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String userId, password;
userId = request.getParameter("userId");
password = request.getParameter("password");
LoginService loginService = new LoginService();
boolean result = loginService.authenticate(userId, password);
if (result) {
response.sendRedirect("login.jsp");
return;
} else {
response.sendRedirect("success.jsp");
return;
}
}
}
EDIT:
@WebServlet("/Testing")
public class Testing extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.sendRedirect("login.jsp");
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.sendRedirect("login.jsp");
}
}
Dies funktioniert jetzt
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="Testing" method="POST">
<input type="text" name="userid"/>
<input type="password" name="password"/>
<input type="submit"/>
</form>
</body>
</html>
posten Sie Ihre web.xml –
es irgendwie funktioniert nun, ein neues Projekt anlegen und mit Tomcat 8.5 statt 9.0, seltsame Sache ist, ... ich habe jetzt nicht Eine web.xml mehr – Reginald