<%!
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 ?
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}
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") %>
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>
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>
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>