|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Generate data entry and reporting .NET Web apps in minutes, straight from your database. Read our FREE whitepaper “Build Web 2.0 Applications Without Hand-Coding” Download now! |
|
#1
|
|||
|
|||
|
I have 2 questions.
First how can I call a servlet from a frame? Second, how can I passed data from a servlet to a jsp? Thanks in advance. |
|
#2
|
|||
|
|||
|
as for the jsp part, I will be learning that in a couple of weeks when I get some projects done. To call a servlet from html frame, you just call the class file.
<FRAME SRC="/servlets/My_Servlet" NAME="body" NORESIZE frameborder="YES" scrolling="YES" bordercolor="#999999"> Usually this is all inside frameset tags or whatever. I hope this is what you were asking... |
|
#3
|
|||
|
|||
|
hi there,
you can add your objects into the HttpServletRequest object and then redirect from your servlet to the jsp page. e.g. from "AServlet.java", passing a String object to the "a.jsp" file. In "AServlet.java": .... ...doGet(HttpServletRequeet req, HttpServletResponse res) { // the jsp file i wanna redirect to String target = "a.jsp"; // creating a String object String hello = "Hello people!"; // add it into the HttpServletRequest object req.setAttribute("hello", hello); // create a dispatch from the ServletContext object // to do the redirection for me =) // don't forget to specify where you wanna go. RequestDispatcher rd = getServletContext().getRequestDispatcher(target); // now here is the magic... you are passing the // HttpServletRequest obj and HttpServletResponse obj // to the jsp page rd.forward(req, res); ..... // code here will not be execute since you have // pass the control to "a.jsp" } .... In the "a.jsp" page, you can retrieve the "hello" object by doing this: <% String hello = (String)request.getAttribute("hello"); out.println(hello); %> It's very helpful by doing this because you can hide all the business logic inside the Servlet and the JSP file will just be doing printing... hope it help. -hoi =) |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Java Help > Servlet and jsp |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|