jsp中的java参数:include

发布于 2024-12-02 02:36:20 字数 298 浏览 0 评论 0原文

我想知道是否可以将 java 变量传递给 .我尝试在 jsp 文件中执行类似的操作:

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

这不起作用。我收到一条错误消息“无法找到资源/=folder/myframe.jsp”。 这可以做到吗?

感谢您的任何帮助。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦行七里 2024-12-09 02:36:20

您需要将页面参数作为整个字符串或整个替换。

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

此外,当在值内连接字符串时,您需要转义双引号。
所以对于你的问题:

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

应该工作正常,或者为了更容易阅读:

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

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 %>" />
红颜悴 2024-12-09 02:36:20

将您的参数名称视为“某物”,
试试这个:

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

其他解决方案是这样做:

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

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

第一个更好,但两者都应该有效。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文