Results 1 to 8 of 8

Thread: Problem in using <c:out> tag with spring

  1. #1
    Join Date
    Oct 2007
    Location
    Mumbai
    Posts
    14

    Default Problem in using <c:out> tag with spring

    I'm writing somthing like this in my Controller Class ExampleController.java
    package model;

    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.ServletException;
    //import java.io.IOException;
    import java.util.*;

    import org.springframework.web.servlet.ModelAndView;
    import org.springframework.web.servlet.mvc.Controller;

    public class ExampleSpring implements Controller {

    public ModelAndView handleRequest(HttpServletRequest request,
    HttpServletResponse response) throws Exception {

    String s=request.getParameter("id");
    System.out.println(s);
    return new ModelAndView("display", "s", s);
    }

    }



    i'm coming to this controller through a jsp viz index.jsp :-

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    <form action="model/gotodisplay">
    <p>Hello Welcome To First SpringFramework Page</p>
    <input type="text" name="id"/>
    <input type="submit" value="display"/>
    </form>
    </body>
    </html>


    in my display. jsp i use <c: out> tag to display the content which i'd entered in index.jsp txt field. my display.jsp looks somthing like this :-

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

    <%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
    <%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt" %>
    <%@ page import="java.util.*,model.*" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
    this is the display jsp<br/><hr/>

    <c: out value="${s}" />
    <br/>
    <center><a href="../index.jsp">Back To Index Page</a></center>
    </body>
    </html>

    my example-servlet.xml is :-

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "/WEB-INF/spring-beans.dtd">
    <beans>

    <bean id="exampleSpring" class="model.ExampleSpring" />

    <bean id="urlMapping"
    class="org.springframework.web.servlet.handler.Sim pleUrlHandlerMapping">
    <property name="mappings">
    <props>
    <prop key="/gotodisplay">exampleSpring</prop>
    <prop key="/index">viewResolver</prop>
    </props>
    </property>
    </bean>

    <bean id="viewResolver"
    class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
    <property name="viewClass">
    <value>org.springframework.web.servlet.view.Jstl Vi ew</value>
    </property>

    </bean>

    </beans>


    my web.xml is like :-

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

    <servlet>
    <servlet-name>example</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
    <servlet-name>example</servlet-name>
    <url-pattern>/model/*</url-pattern>
    </servlet-mapping>


    <display-name>first-sprigapp</display-name>
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    </web-app>


    can u please help and tell me what i'm doing wrong. i'm not able to see the output when i'm using <c: out> tag
    Sushant Singh Pawar
    Software Developer
    3i-Infotech
    Mumbai

  2. #2
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,806

    Default

    Code:
    <%@ taglib uri="/WEB-INF/c.tld" prefix="c" %>
    ???

    i suggest, see the spring examples
    and this topic was discussed before

    let me know your advance, and use code tags, without that is cumbersome see your code, so yourself avoid help

    regards
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  3. #3
    Join Date
    Oct 2007
    Location
    Mumbai
    Posts
    14

    Default

    sir,
    i'd written this coz since i was have some problem in net connection so i imported this tld and written this insted of writing <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>. about cumbersome ya it is lil bit but its just a test code so thats y...

    Please help me in all possible way
    Sushant Singh Pawar
    Software Developer
    3i-Infotech
    Mumbai

  4. #4
    Join Date
    Dec 2005
    Location
    Croatia
    Posts
    192

    Default

    Quote Originally Posted by sushant.pawar View Post
    about cumbersome ya it is lil bit but its just a test code so thats y...
    He was refering that you did not put your code inside [ CODE ] [ /CODE ] tags when writing your post, lol.

    Why don't you start by explaining what error do you see? Does your page displays ok, but <c: out> tags displays nothing? Does your page displays at all? Is there any error messages?

    People here generaly don't have much time to analyze your code in detail...so you should provide as much info as possible.


    Regards,
    Igor.

  5. #5
    Join Date
    Oct 2007
    Location
    Mumbai
    Posts
    14

    Default

    i'm not getting any error by this code. just <c: out value="${s}"> is not printing anythig. just this. y i don't know.
    Sushant Singh Pawar
    Software Developer
    3i-Infotech
    Mumbai

  6. #6
    Join Date
    Aug 2006
    Location
    Arequipa-Peru / South America
    Posts
    2,806

    Default

    Code:
    String s=request.getParameter("id");
    System.out.println(s);
    return new ModelAndView("display", "s", s);
    seems good

    i'd written this coz since i was have some problem in net connection so i imported this tld and written this insted of writing <%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>.
    mmm, wondered ,
    uri="http://java.sun.com/jstl/core" is just a namespace,
    it dont call to internet to work if you think that
    - Manuel Jordan

    Kill Your Pride, Share Your Knowledge With All
    The Fear Of The LORD Is The Beginning Of Knowledge, But Fools Despise Wisdom And Discipline. Proverbs 1:7

    Blog


    Technical Reviewer of Apress

    • Pro SpringSource dm Server
    • Spring Enterprise Recipes: A Problem-Solution Approach
    • Spring Recipes: A Problem-Solution Approach, 2nd Edition
    • Pro Spring Integration
    • Pro Spring Batch
    • Pro Spring 3
    • Pro Spring MVC: With Web Flow
    • Pro Spring Security

  7. #7
    Join Date
    Sep 2004
    Location
    Manchester, NH
    Posts
    1,236

    Default

    Quote Originally Posted by sushant.pawar View Post
    i'm not getting any error by this code. just <c: out value="${s}"> is not printing anythig. just this. y i don't know.
    Try doing something simple first, without assuming Spring is working, e.g.
    Code:
    <c:out value="7"/>
    This will help you narrow down the problem, which I'm sure is related to your use of JSTL, and not Spring.

    dr_pompeii is correct that you should be including the full URI to java.sun.com, and don't need to reference the TLD directly, since you are using a servlet 2.4-compatible webapp (this used to be required, but hasn't been required for some time).

    Depending on the servlet container, you may need the following URI reference instead:
    Code:
     <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
    Once you get that resolved, then we'll figure out if there's something wrong with the way you're trying to use Spring. A common beginner mistake is to try to access the .jsp directly (e.g. http://.../myapp/index.jsp) instead of through the Spring URL mappings (for you, this would look something like http://.../myapp/gotodisplay).

    Good luck!
    Peter Mularien | Blog
    Author, Spring Security 3 (Book) - Packt Publishing, Available in print and eBook form
    SCJP 5, Oracle DBA
    Any postings are my own opinion, and should not be attributed to my employer or clients.


  8. #8
    Join Date
    Apr 2006
    Posts
    6

    Default

    Sushant, have you checked whether 'c' tag works at all in your page.
    Try
    <c:set var="s1" value="abcd"/>
    <c:out value="${s1}" />
    if it works try,
    <c:if test="${empty s}">some text</c:if>
    If you got "some text", then your parameter s is not passed properly to jsp.
    First narrow-down your problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •