Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Display Servlet Output into JSP Page

  1. #1
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Display Servlet Output into JSP Page

    Hello Friends,

    I want to show the output return by the below given servlet into jsp page .
     
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
     
    public class GetAllProgrammesServlet extends HttpServlet
    {
    	public void service(HttpServletRequest request, HttpServletResponse response)
    		throws IOException, ServletException
    	{
                PrintWriter pw = response.getWriter();
                Transactions tr = new Transactions();
     
                try
                {
                    String programmes = tr.getProgrammes();
     
                    if(programmes.length() > 0)
                    {
    [B]                    pw.println(programmes);
    [/B]                    return;
                    }
                    else
                    {
                        pw.println("NULL");
                    }
                }
                catch(Exception ex)
                {
                    pw.println("exception");
                    ex.printStackTrace();
                }
    	}
    }


    where
    programmes="P0001,MCA,0$P0002,MBA,1";

    in jsp page i want to split it into different pieces and want to show them in tabular form
    for that i want to contain the output return by this servlet into a variable.

    Please put some light..Its urgent.

    i had tried various ways.i am able to show the content into jsp by using include scriplet , but unable to store into variable.
    Thanks and Regards
    Dan Brown

    Common Java Mistakes


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Display Servlet Output into JSP Page

    Why try to include the servlet, as the code is quite simple and can just placed into the jsp page. Serlets and jsp pages are to output data to clients...if you want cross talk then perhaps remove the commonalities into another object which can be used by both...in other words if you have more complex things going on than just this, create a POJO that accomplishes what you need which can be instantiated and used by multiple servelts/jsp pages

  3. #3
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Re: Display Servlet Output into JSP Page

    Transactions tr = new Transactions()

    this class is in web-inf/classes folder

    Transaction is an helper java class.

    And my Jsp page is outside the web-inf where we generally put our html pages.
    When i m trying to created object of Transcation class in jsp page,then it shows transaction class not available.

    i feel it is possible to use transaction class there because , we can directly call servlets putted in web-inf/classes
    folder.
    Am i right or wrong ?
    Please put some light..
    thank you all..
    Thanks and Regards
    Dan Brown

    Common Java Mistakes

  4. #4
    Super Moderator Json's Avatar
    Join Date
    Jul 2009
    Location
    Warrington, United Kingdom
    Posts
    1,274
    My Mood
    Happy
    Thanks
    70
    Thanked 156 Times in 152 Posts

    Default Re: Display Servlet Output into JSP Page

    Does the JSP page have an import statement in it to import the Transactions class?

    Also, best practice is to avoid using scriptlet inside the JSP, it's not nice, it clutters it and you should override the doGet and doPost methods rather than the service method of HttpServlet.

    In order to forward a user from your servlet to a JSP you can use the requestDispatcher found on the request object.

    // Json

Similar Threads

  1. What are the requirements to develop Servlet Application?
    By yousef atya in forum Java Servlet
    Replies: 2
    Last Post: July 28th, 2011, 06:20 PM
  2. Servlet or Jsp?
    By flangofas in forum JavaServer Pages: JSP & JSTL
    Replies: 3
    Last Post: December 8th, 2010, 11:54 AM
  3. reg how to use log in jsp page
    By javaking in forum JavaServer Pages: JSP & JSTL
    Replies: 7
    Last Post: April 9th, 2010, 12:36 AM
  4. Need help in JSP Page
    By vinothkumarrvk in forum Web Frameworks
    Replies: 1
    Last Post: March 12th, 2010, 07:43 AM
  5. Need help in JSP Page
    By vinothkumarrvk in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: March 9th, 2010, 05:20 AM