February 28th, 2001, 10:35 AM
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.
February 28th, 2001, 12:12 PM
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...
February 28th, 2001, 06:14 PM
add it into request object...
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.
...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
// 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
// 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");
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.