在jsp中传递java变量:param

发布于 2024-10-27 01:34:03 字数 324 浏览 4 评论 0 原文

 <%!  
    String str = "prerna";  
  %>  

 <jsp:include page="index.html">
      <jsp:param name="type1" value=<%=str%> >
      </jsp:param>  
 </jsp:include>

我想在 param 标记中传递一个 java 变量,但我不知道该怎么做。

我还想在 index.html 中访问它。
谁能建议我该怎么做?

 <%!  
    String str = "prerna";  
  %>  

 <jsp:include page="index.html">
      <jsp:param name="type1" value=<%=str%> >
      </jsp:param>  
 </jsp:include>

I want to pass a java variable in the param tag,but i am not sure how to do it.

I also want to access it in index.html.
Can anyone suggest me the way to do it ?

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

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

发布评论

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

评论(6

萌吟 2024-11-03 01:34:03

直接放入value即可。

<jsp:include page="index.html">
    <jsp:param name="type1" value="prerna" />
</jsp:include>

或者使用 JSTL 来设置它,并使用 EL ${} 来获取它。

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
<c:set var="type1" value="prerna" />
...
<jsp:include page="index.html">
    <jsp:param name="type1" value="${type1}" />
</jsp:include>

如果您包含的页面是 jsp,那么您可以将其用作 ${param.type1}

Just put it in value directly.

<jsp:include page="index.html">
    <jsp:param name="type1" value="prerna" />
</jsp:include>

Or use JSTL <c:set> to set it and EL ${} to get it.

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
<c:set var="type1" value="prerna" />
...
<jsp:include page="index.html">
    <jsp:param name="type1" value="${type1}" />
</jsp:include>

And if your included page is a jsp, then you can use it as ${param.type1}

芯好空 2024-11-03 01:34:03

请求参数可以使用
传递
可以使用 标记将参数名称和值传递到转发的文件 示例

例如:

HTML :

<html>
<head>
<title></title>
</head>
<body>
<jsp:forward page="ssParameters.jsp">
  <jsp:param name="myParam" value="Amar Patel"/>
  <jsp:param name="Age" value="15"/>
</jsp:forward>
</body>
</html>   

标签用于将名称和值传递到目标文件。这些参数将由目标文件使用 request.getParameter() 方法检索。通过这种方式,可以传递和检索参数。

This page had a parameter forwarded to it:<br>
  <b>Name:</b> <%= request.getParameter("myParam") %><br>
  <b>Age:</b> <%= request.getParameter("Age") %>

Request parameters can be passed by using <jsp: param>
One can pass the parameter names and values to the forwarded file by using a <jsp: param> tag

Sample e.g :

HTML :

<html>
<head>
<title></title>
</head>
<body>
<jsp:forward page="ssParameters.jsp">
  <jsp:param name="myParam" value="Amar Patel"/>
  <jsp:param name="Age" value="15"/>
</jsp:forward>
</body>
</html>   

<jsp:param> tag is used to pass the name and values to the targeted file. These parameters will be retrieved by the targeted file by using request.getParameter() method. In this way one can pass and retrieve the parameters.

This page had a parameter forwarded to it:<br>
  <b>Name:</b> <%= request.getParameter("myParam") %><br>
  <b>Age:</b> <%= request.getParameter("Age") %>
め七分饶幸 2024-11-03 01:34:03

将参数传递给 jsp jstl:

/* JSP PARENT */

<jsp:include page="../../templates/options.jsp">                    
    <jsp:param name="action" value="${myValue}"/>       
</jsp:include>


/* JSP CHILD (options.jsp)*/

<div id="optionButtons left">       
    <span>${param.action}</span>
</div>

To pass parameters to a jsp jstl:

/* JSP PARENT */

<jsp:include page="../../templates/options.jsp">                    
    <jsp:param name="action" value="${myValue}"/>       
</jsp:include>


/* JSP CHILD (options.jsp)*/

<div id="optionButtons left">       
    <span>${param.action}</span>
</div>
七堇年 2024-11-03 01:34:03

只是<%=str%>;用双引号括起来应该可以,我希望这是您问题的答案。

<%!  
    String str = "prerna";  
%>  

<jsp:include page="index.html">
      <jsp:param name="type1" value="<%=str%>" />  
</jsp:include>

just but the <%=str%> in double quotes this should work , i hope this is an answer to your question.

<%!  
    String str = "prerna";  
%>  

<jsp:include page="index.html">
      <jsp:param name="type1" value="<%=str%>" />  
</jsp:include>
一刻暧昧 2024-11-03 01:34:03

使用 request.setAttribute() 您可以将 Java 变量传递给 JSP。

 <%  
    String str = "prerna";

    request.setAttribute("myVar",str);
  %>  

 <jsp:include page="index.html">
      <jsp:param name="type1" value="${myVar}" >
      </jsp:param>  
 </jsp:include>

Using request.setAttribute() you can pass the Java variable to the JSP.

 <%  
    String str = "prerna";

    request.setAttribute("myVar",str);
  %>  

 <jsp:include page="index.html">
      <jsp:param name="type1" value="${myVar}" >
      </jsp:param>  
 </jsp:include>
无人问我粥可暖 2024-11-03 01:34:03

"<%=str%>" 添加双引号;

<%
  String str = "prerna";
%>

<jsp:include page="index.html">
    <jsp:param name="type1" value="<%=str%>">
    </jsp:param>
</jsp:include>

Add double quotes for your value "<%=str%>" in <jsp:param .... value="<%=str%>"/>

<%
  String str = "prerna";
%>

<jsp:include page="index.html">
    <jsp:param name="type1" value="<%=str%>">
    </jsp:param>
</jsp:include>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文