JSF Servlet导致奇怪的行为

时间:2013-10-10 13:47:57

标签: java jsf servlets

我有一个servlet,其目的是根据传递给它的参数将人重定向到页面。但是,当我重定向到某个页面时,点击的任何按钮都会导致该页面重定向到我的目标网页。

控制器:

@WebServlet(name = "Case1Controller", urlPatterns = {"/C1Control"})
public class Case1Controller extends HttpServlet {

protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        String jsf = request.getParameter("jsf");
        if(jsf.equalsIgnoreCase("V")) {
    response.sendRedirect(response.encodeRedirectURL("AddVendor.jsf"));
        }
        if(jsf.equalsIgnoreCase("P")) {
    response.sendRedirect(response.encodeRedirectURL("AddProduct.jsf"));
        }
        if(jsf.equalsIgnoreCase("O")) {
    response.sendRedirect(response.encodeRedirectURL("POGenerator.jsf"));
        }
    }
}

@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";
}

}

用法:

 < ul>
      < m:MenuItem caption="Add Vendor" jsf="V"/>
      < m:MenuItem caption="Add Product" jsf="P"/>
      < m:MenuItem caption="Generate PO" jsf="O"/>
 < /ul>

菜单项控件:

<!-- INTERFACE -->
<cc:interface>
    <cc:attribute name="caption" required="true"/>
    <cc:attribute name="jsf" required="true"/>
</cc:interface>

<!-- IMPLEMENTATION -->
<cc:implementation>
    <h:outputLink value="/Info5059Case1/C1Control?jsf=#{cc.attrs.jsf}"> #{cc.attrs.caption}</h:outputLink>&nbsp;

</cc:implementation>

1 个答案:

答案 0 :(得分:2)

按钮中的某些内容是否会导致异常被抛出而你没有抓到?这可能导致控制器重定向您。