2012-12-10 38 views
0

我試圖包含'home.jsp'文件或'error.jsp'文件。這是我的servlet文件和我的模板:動態地在主視圖中包含jsp文件

// 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> 

我得到日食此錯誤:

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

回答

0

錯誤很明顯。

main.jsp期待,你必須使用jsp:paramquerystring main.jsp?name=value

通過

無論是參數