JSP Help Required?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: JSP Help Required?

Hybrid View

  1. #1
    Join Date
    Mar 2006
    Location
    Multan, Pakistan
    Posts
    4

    Question JSP Help Required?

    hi All

    I have develpoed a small application in java. which contains on one servler and one jsp page.
    ...................

    Here is the servlet code:

    ............................
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;

    public class Controller extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html";

    //Initialize global variables
    public void init() throws ServletException {
    }

    //Process the HTTP Get request
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType(CONTENT_TYPE);
    // PrintWriter out = response.getWriter();
    String teststring = "Good";
    request.setAttribute("Noman", teststring);
    RequestDispatcher reqdispatcher = this.getServletConfig().getServletContext().getRequestDispatcher("model1.jsp");
    reqdispatcher.forward(request,response);
    }

    //Clean up resources
    public void destroy() {
    }
    }

    .................................................

    and here is the jsp page code:

    ................................................

    <html>
    <head>
    <title>
    model1
    </title>
    </head>
    <body bgcolor="#ffffff">
    <!--<form method="GET" action="Controller">

    JBuilder Generated JSP
    </form><-->
    <% String a = (String)request.getAttribute("Noman"); %>
    <%= a %>
    </body>
    </html>

    I want to pass a string (teststring) value from servlet to jsp page.
    but when i run the jsp page. it displays null value in string.
    Where is the error.
    i tried it a lot but can not find error in code.

    plz help me.

    Response will be highly appriciated

    Thanks
    Nomi

  2. #2
    Join Date
    Sep 2006
    Posts
    6
    try request.getParameter();

  3. #3
    Join Date
    Sep 2006
    Location
    hyderabad
    Posts
    5

    use by url rewritting

    request.setAttribute("Noman", teststring);
    RequestDispatcher reqdispatcher = this.getServletConfig().getServletContext().getRequestDispatcher("model1.jsp");

    instead of abow code, use following code (url rewritting.)

    String url="model1.jsp?Noman="+teststring;
    RequestDispatcher reqdispatcher = this.getServletConfig().getServletContext().getRequestDispatcher(url);

    Then use below code in jsp

    Then u will get the value by using request.getParameter("Noman")

Similar Threads

  1. Servlets and JSP
    By Purnima in forum Java
    Replies: 1
    Last Post: 12-29-2005, 05:14 AM
  2. Replies: 1
    Last Post: 09-07-2001, 04:03 PM
  3. Replies: 1
    Last Post: 09-07-2001, 04:03 PM
  4. JSP and the <SERVLET> tag
    By Dusty in forum Java
    Replies: 2
    Last Post: 04-07-2000, 02:20 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center