2016-08-10 8 views
0

私は、次のJavaサーブレットを持って、アプリケーションが "/パス" で動作しますが、ないと "/パス/に"

package com.controller; 

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 Teste extends HttpServlet { 

    protected void processRequest(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException { 
     response.setContentType("text/html;charset=UTF-8"); 
     request.setAttribute("teste", "MothaFucka"); 
     request.getSession().setAttribute("teste", "MothaFucking Session"); 
     RequestDispatcher rd = request.getRequestDispatcher("teste.jsp"); 
     rd.forward(request, response); 
    } 

    @Override 
    protected void doGet(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException { 
     processRequest(request, response); 
    } 

    @Override 
    protected void doPost(HttpServletRequest request, HttpServletResponse response) 
      throws ServletException, IOException { 
     processRequest(request, response); 
    } 

    @Override 
    public String getServletInfo() { 
     return "Short description"; 
    } 

} 

そして次web.xmlファイル:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app version="3.1" 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"> 
    <servlet> 
     <servlet-name>Teste</servlet-name> 
     <servlet-class>com.controller.Teste</servlet-class> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>Teste</servlet-name> 
     <url-pattern>/teste</url-pattern> 
    </servlet-mapping> 
    <session-config> 
     <session-timeout> 
      30 
     </session-timeout> 
    </session-config> 
</web-app> 
私はURLでサーブレットにアクセスすることができます

http://localhost:8084/myapp/teste

私がしたいことは/teste/editにURLパターンを変更ですが、私はそれを行う、とthrouサーブレットにアクセスしようとすると、 gh the url http://localhost:8084/myapp/teste/edit次の404エラーが表示されます。

HTTP Status 404 - /TrabalhoPSW/teste/teste.jsp

type Status report

message /TrabalhoPSW/teste/teste.jsp

description The requested resource is not available. Apache Tomcat/8.0.27

なぜこのようなことが起こりますか?これをどうすれば解決できますか?

答えて

0

問題は、サーブレットが検索しようとしていたJSPファイルです。私は

request.getRequestDispatcher("/teste.jsp"); 

request.getRequestDispatcher("teste.jsp"); 

から変更されたときには正常に働いていました。

0

あなたのサーブレットがに/パス/パス/で動作するよりも、必要がある場合にweb.xmlのサーブレットのマッピングを変更します。

<url-pattern>/teste/*</url-pattern> 
関連する問題