-
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
-
try request.getParameter();
-
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
-
Replies: 1
Last Post: 12-29-2005, 04:14 AM
-
By Adam Dawes in forum VB Classic
Replies: 1
Last Post: 09-07-2001, 03:03 PM
-
By Adam Dawes in forum VB Classic
Replies: 1
Last Post: 09-07-2001, 03:03 PM
-
Replies: 2
Last Post: 04-07-2000, 01: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
Forum Rules
|
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
|
Bookmarks