pass java variable in jsp:param

2019-03-12 06:16发布

 <%!  
    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 ?

5条回答
女痞
2楼-- · 2019-03-12 06:52

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>
查看更多
欢心
3楼-- · 2019-03-12 06:58

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>
查看更多
干净又极端
4楼-- · 2019-03-12 07:05

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}

查看更多
【Aperson】
5楼-- · 2019-03-12 07:05

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") %>
查看更多
你好瞎i
6楼-- · 2019-03-12 07:14

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>
查看更多
登录 后发表回答