在主视图中动态包含jsp文件

时间:2012-12-10 03:50:48

标签: java jsp

我尝试包含'home.jsp'文件或'error.jsp'文件。这是我的servlet文件和我的模板:

// servlet

...
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
{

            // api access
        Api apix  = new Api(new ApiRequest(-1));

        // post params
        String email = request.getParameter("email");
        String password = request.getParameter("password");

        // exists?
        User user =  apix.userManager.authenticate(email, password);

        // template
        String address = "/main.jsp";

                // variable content
        String content_page = "/WEB-INF/user/home.jsp";


        if (user == null)
        {
            content_page = "/error.jsp";
        }

        request.setAttribute("content_page", content_page);
        RequestDispatcher dispatcher = request.getRequestDispatcher(address);

        dispatcher.forward(request, response);


}

// main.jsp

<head>
    <jsp:include page="/head_includes.jsp"/>
</head>

<body>

    <% 
        String content_page = request.getParameter("content_page");

        if (content_page == null)
        {
            content_page = "/error.html";
        }

    %>

            <!-- I get an error here -->
            **<jsp:include page="<%= content_page %>">**
</body>

我在eclipse上遇到这个错误:

org.apache.jasper.JasperException: /main.jsp (line: 29, column: 1) Expecting "jsp:param" standard action with "name" and "value" attributes

1 个答案:

答案 0 :(得分:0)

错误很明显。

main.jsp期待您必须传递的参数

使用jsp:paramquerystring main.jsp?name=value