开发者

java parameter in jsp:include

开发者 https://www.devze.com 2023-04-01 11:15 出处:网络
I wanted to know if I can pass a java variable to a . I tried to do something like this inside a jsp file:

I wanted to know if I can pass a java variable to a . I tried to do something like this inside a jsp file:

<% String folder = request.getParameter("something"); %>
<jsp:include page="../<%=folder%>开发者_如何学编程/myframe.jsp" ></jsp:include>

This does not work. I get an error which says 'Failed to find resource /=folder/myframe.jsp'. Can this be done?

Thanks for any help.


You either need to have the page parameter as an entire string or as an entire substitution.

<jsp:include page="<%= myPageToInclude %>" />
<jsp:include page="path/to/my/page.jsp" />

Also when concatenating strings inside a value you need to escape the double quotes. So for your problem :

<% String folder = request.getParameter("something"); %>
<jsp:include page="<%= \"../\" + folder + \"/myframe.jsp\" %>" />

Should work fine, or for easier reading :

<% 
    String folder = request.getParameter("something");
    String page = "../" + folder + "/myframe.jsp";
%>
<jsp:include page="<%= page %>" />


Concidering your param name as "something", Try this:

<jsp:include page="../${param.something}/myframe.jsp" />

Other solution is to do that:

<% String folder = request.getParameter("something"); %>
<% pageContext.setAttribute("folder", folder); %>

<jsp:include page="../${folder}/myframe.jsp"></jsp:include>

First is better but both should works.

0

精彩评论

暂无评论...
验证码 换一张
取 消