JSTL Core c:out

<c:out> renders data to the JSP page.It just like println() method of PrintWriter to print data.It prints the value of variable stored in any scope like request,session etc. Example below to print a value store in a variable in a request scope.

FirstServlet .java

  import javax.servlet.http.*; 
  import javax.servlet.*; 
  import java.io.*; 
  public class FirstServlet extends HttpServlet{ 
  public void doGet(HttpServletRequest request,HttpServletResponse response) 
  throws ServletException,IOException {
  request.setAttribute("msg","Thanks for visiting our site");  
  RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/jsp/hello.jsp");
  rd.include(request,response); }  } 
 

hello.jsp

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

Leave a Reply