Hi,
I want to pass an object from a jsp to a servlet. I've tried to use request.setAttribute("Object", object) in the jsp page and call the object in my servlet using request.getAttribute("Object"). Unfortunately did work. Could anybody help me with this and give expample code? I'm new to JSP and please don't slaughter me when this is a pretty easy and stupid question ;-)
Cheers
-
Passing an object from jsp to servlet (4 messages)
- Posted by: Silke Langenberg
- Posted on: January 29 2005 12:13 EST
Threaded Messages (4)
- Passing an object from jsp to servlet by Matt Weaver on February 01 2005 10:25 EST
- JSP TO SERVLET Passing Object by ss ssss on February 24 2005 06:25 EST
- Passing an object from jsp to servlet by sachin desai on April 25 2005 05:28 EDT
- To pass an object from jsp to servlet by dhaval chavda on March 17 2010 03:10 EDT
-
Passing an object from jsp to servlet[ Go to top ]
- Posted by: Matt Weaver
- Posted on: February 01 2005 10:25 EST
- in response to Silke Langenberg
Inside the JSP you want to use response.setAttribute("obj", obj); The response is what will be sent to the Servlet.
You could also stick it in the session (just be sure to clean up afterwards or you will get an "over-stuffed session").
Normally you get POST data from a form and create your objects in a Servlet (request.getParameter("")) instead of (request.getAttribute(""), assuming you set it).
You should seek to minimize Java code in jsps (that's what tlds are for). This makes the front end easier for non-developers to create (what is all this junk in my HTML?). Otherwise, you are running into the danger of making big, complicated jsps that contain way too much java code. This is actually symptomatic of an anti-pattern (monolithic jsp). I have seen jsps that are several thousand lines of mostly java code. Don't let that happen to you! -
JSP TO SERVLET Passing Object[ Go to top ]
- Posted by: ss ssss
- Posted on: February 24 2005 06:25 EST
- in response to Silke Langenberg
hi,
to pass a object from JSP Page to Servlet you use the method
doPost(HttpServletRequest request, HttpServletResponse response)
or
doGet(HttpServletRequest request, HttpServletResponse response)
eg.
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class greetServlet extends HttpServlet
{
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException
{
//Get Parameters from the request
String name=request.getParameter("name");
String email=request.getParameter("email");
String message=null;
}
} -
Passing an object from jsp to servlet[ Go to top ]
- Posted by: sachin desai
- Posted on: April 25 2005 05:28 EDT
- in response to Silke Langenberg
please fwd the same info to me.
thanking you.
Sachin. -
To pass an object from jsp to servlet[ Go to top ]
- Posted by: dhaval chavda
- Posted on: March 17 2010 03:10 EDT
- in response to Silke Langenberg
hey dear.if u not getting with setAttribute and getAttribute than make use of usebean.take usebean in between and in that set a value for ur object and get in servlet page.u will get it.