DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 3 of 3
  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, 04:14 AM
  2. Replies: 1
    Last Post: 09-07-2001, 03:03 PM
  3. Replies: 1
    Last Post: 09-07-2001, 03:03 PM
  4. JSP and the <SERVLET> tag
    By Dusty in forum Java
    Replies: 2
    Last Post: 04-07-2000, 01:20 PM

Bookmarks

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


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links