2016-03-29 9 views
1

私はただエラー404を取得します:要求されたリソースは利用できません。サーブレットの応答はリダイレクトエラーを送信します

<?xml version="1.0" encoding="UTF-8"?> 
<web-app 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_3_1.xsd" 
     version="3.1"> 
    <servlet> 
     <servlet-name>servlet</servlet-name> 
     <servlet-class>controller.Servlet</servlet-class> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>servlet</servlet-name> 
     <url-pattern>/login</url-pattern> 
    </servlet-mapping> 
</web-app> 

サーブレット:

[@WebServlet(name = "controller.Servlet") 
public class Servlet extends HttpServlet { 
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
     String id = request.getParameter("id"); 
     String password = request.getParameter("password"); 

     if (LoginService.authentication(id, password)) { 
      response.sendRedirect("succes.jsp"); 
     } else { 
      response.sendRedirect("index.jsp"); 
     } 
     return; 
    }][1] 

index.jspファイル:

<%@ page contentType="text/html;charset=UTF-8" language="java" %> 
<html> 
<head> 
    <title>Login Page</title> 
</head> 
<body> 
<form action="/login" method="post"> 
    Username: <input type="text" name="id" > 
    <br> 
    Password: <input type="password" name="password"> 
    <br> 
    <input type="submit" value="submit"> 
</form> 
</body> 
</html> 

これはXMLが

です:私はここで間違っているかを把握することはできませんsucces.jsp:

<%@ page contentType="text/html;charset=UTF-8" language="java" %> 
<html> 
<head> 
    <title>Login Succesfully</title> 
</head> 
<body> 
    <h1>Login succesfully</h1> 
</body> 
</html> 

そして、これはフォルダ構造である:別の方法としては、このように@WebServletでurlPatternsを定義するとweb.xmlからサーブレット定義およびURLパターンを削除することができます

<servlet> 
      <servlet-name>controller.Servlet</servlet-name> 
      <servlet-class>com..Servlet(replace with your servlet class namespace)</servlet-class> 
    </servlet> 

http://i.stack.imgur.com/ZGMH4.png

答えて

0

更新のweb.xml

@WebServlet(name="controller.Servlet", urlPatterns={"/login"}) 
public class Servlet extends HttpServlet{ 
....... 
} 

のweb.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app 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_3_1.xsd" 
     version="3.1"> 

</web-app> 
+0

別の問題は、彼がWEB-INF/succes.jspにリダイレクトしようとしていることです – rickz

関連する問題