1

我有一个 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>
4

1 回答 1

2

您的按钮中是否有某些东西导致抛出您没有捕捉到的异常?这可能会导致控制器重定向您。

于 2013-10-10T14:14:37.013 回答