pass java variable in jsp:param

后端 未结 5 1654
耶瑟儿~
耶瑟儿~ 2021-02-04 03:37
 <%!  
    String str = \"prerna\";  
  %>  

 
       >
      

        
相关标签:
5条回答
  • 2021-02-04 03:43

    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}

    0 讨论(0)
  • 2021-02-04 03:54

    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>
    
    0 讨论(0)
  • 2021-02-04 03:58

    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") %>
    
    0 讨论(0)
  • 2021-02-04 04:00

    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>
    
    0 讨论(0)
  • 2021-02-04 04:05

    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>
    
    0 讨论(0)
提交回复
热议问题