开发者

C:out tag in jstl

开发者 https://www.devze.com 2023-04-12 16:35 出处:网络
I am new to jstl.This is my code. hello.jsp <%@ page contentType=\"text/html\" %> <%@ taglib prefix=\"c\" uri=\"http://java.sun.com/jstl/core\" %>

I am new to jstl.This is my code.

hello.jsp

  <%@ page contentType="text/html" %> 
 <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
 <html> 
 <body> 
  <form method="GET" action="jstl-choose-tag.jsp" > 
 Select an operation and click the button<br /><br /> 
<input type="radio" name="radioBtnGroup" value="uCaseOp" />Convert a string to upper    Case<br /> 
<input type="radio" name="radioBtnGroup" value="lCaseOp" />Convert a string to lower Case<br /> 

 <br /> 
<input type="Submit" /> 
 </form> 


 </body> 
 </html> 

jstl-choose-tag.jsp:

   <%@ page contentType="text/html" %> 
   <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> 
   <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %> 

  <开发者_如何学Python;html> 
  <body>
    <c:if test="${pageContext.request.method=='GET'}">
    <c:out value="${param.radioBtnGroup}" />
  <c:out value="${param.radioBtnGroup}" />
  </c:if> 

<a href="hello.jsp"> Back</a> 
  </body> 
 </html> 

the output which I get is

 ${param.radioBtnGroup} ${param.radioBtnGroup}

Can anyone help me.Thanks in advance.


The symptoms indicate that the JSTL tags are successfully been parsed and executed (otherwise you wouldn't see ${foo} in the browser at all), but the EL expressions are not evaluated (you're seeing literally ${foo} in the browser).

This can happen when your web.xml is not declared conform at least Servlet 2.4 / JSP 2.0. If your web.xml is declared conform Servlet 2.3 or lower, or has a broken declaration, then EL expressions in JSP 2.0 compatible taglibs won't be evaluated at all.

For proper web.xml declaration examples, check the bottom of our JSTL wiki page. Assuming that you're targeting a Servlet 2.5 capable container (e.g. Tomcat 6.0, Glassfish 2.x, etc), then your web.xml should be declared conform Servlet 2.5:

<?xml version="1.0" encoding="UTF-8"?>
<web-app 
    xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">

    <!-- Config here. -->

</web-app>


The el tag libraries must be referenced by

<%@ taglib prefix = "c" uri = "http://java.sun.com/jstl/core" %>

NOT BY

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

If the questioner switches it over there's a good chance it'll pick up the right library, so long as the appropriate jar is in the classpath. Curiously enough, this worked for me even though I was declaring servlet 2.3 (not 2.4 or later) in my web.xml so that doesn't seem crucial. I'm using Tomcat as my servlet container.


Actually you have not included jar file which has to be there to run any jstl. if you are using maven then you can add dependencies otherwise you have to add jar file. click here for reference

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号