为什么我的转发没有传递到Servlet类?

时间:2019-02-15 14:43:49

标签: jsp servlets java-ee forward

我用java ee,Tomcat 9开发了一个站点。IDE Eclipse我在登录页面中有一个表单,该表单提交给LoginServlet以获取特征,并在获得特征后转发到主页。 但是通过调试和结果,我发现我从未传递给HomeServlet。

我已经尝试更改路径,将操作更改为表单

这是web.xml

<!-- Servlet CONNEXION -->
<servlet> 
<servlet-name>ConnexionServlet</servlet-name>
<servlet-class>servlets.ConnexionServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>ConnexionServlet</servlet-name>
<url-pattern>/connexion</url-pattern>
</servlet-mapping> 
<!-- Servlet ACCUEIL -->
<servlet> 
<servlet-name>AccueilServlet</servlet-name>
<servlet-class>servlets.AccueilServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>AccueilServlet</servlet-name>
<url-pattern>/accueil</url-pattern>
</servlet-mapping>  

connexion.jsp的动作     

转到ConnexionServlet获取特征,然后转到主页

private static final long serialVersionUID = 1L;
private static final String VUE ="/WEB-INF/connexion.jsp";
private static final String VUE_ACCUEIL="/WEB-INF/accueil.jsp";

//Premier affichage de la page
protected void doGet(HttpServletRequest request , HttpServletResponse response) throws ServletException, IOException {
            this.getServletContext().getRequestDispatcher(VUE).forward(request, response);
}

public void doPost(HttpServletRequest request , HttpServletResponse response) throws ServletException, IOException{

    ConnexionTraitement conT = new ConnexionTraitement();
     boolean go=false;
    try {
        go = conT.connexionCliente(request);
    } catch (SQLException e) {
        System.out.println(e.getMessage());
        e.printStackTrace();
    }
    if(go) {
        /*System.out.println(request.getRequestURI());
         String newRequest = request.getRequestURI() ;
         System.out.println( "servlet path"+request.getServletPath());
         newRequest = "/doyourhair/accueil";
         System.out.println(request.getRequestURI());*/


   this.getServletContext().getRequestDispatcher(VUE_ACCUEIL).forward(request, response);
    }else {
        this.getServletContext().getRequestDispatcher(VUE).forward(request, response);

    }
}

它应该转到家庭服务器(我有类似从数据库加载列表的处理,所以它是动态的),并在显示页面之后

但是,当我提交时,它会转到连接servlet等,只是在没有我的列表的情况下简单地首页

0 个答案:

没有答案