Using a WEB engine that supports both JSP .92 and JSDK 2.0:
1)The servlet that makes the decision can also be a JSP
2)Sample code looks like
<%
String action = servletrequest.getParameter("action");
if (action.equals("login"))
getServletConfig().getServletContext().getRequestDistpatcher("login.jsp").forward(servletrequest,servletresponse);
else if (action.equals("mainmenu"))
ServletConfig().getServletContext().getRequestDistpatcher("mainmenu.jsp").forward(servletrequest,servletresponse);
%>
Gabriel Wong
http://www.ezwebtools.com
----------------------------
Dave Fabrizi wrote:
> I need to Call a servlet which will then make a decision as to which JSP
> page get called.
> (all on the server side)
>
> I received this message some time ago but have since moved on to JSP 0.92.
> Since this example will not work with JSP 0.92, could I get new example.
>
> David A. Fabrizi
>
> -----Original Message-----
> From: A mailing list about Java Server Pages specification and reference
> [mailto:[EMAIL PROTECTED]]On Behalf Of Kirkdorffer, Daniel
> Sent: Wednesday, February 03, 1999 2:20 PM
> To: [EMAIL PROTECTED]
> Subject: Re: JSP Access Models
>
> Rich,
>
> We've been primarily using the second model, where a call is made to a
> servlet which calls a JSP page.
>
> There isn't a lot to do really. You process the servlet call as you wish,
> perhaps going to a database or whatever using JDBC, and then decide how to
> respond. Since we're using the 0.91 spec, I'll provide code examples for
> 0.91.
>
> Once you have decided how to respond, perhaps created a Bean, you can set
> any <BEAN> data in your JSP with a setAttribute call:
>
> for example:
>
> ((HttpServiceRequest)req).setAttribute("results", resultObject);
>
> Then you invoke the JSP file:
>
> ((HttpServiceResponse)resp).callPage("myData.jsp", req);
>
> The JSP file will have a <BEAN> tag in it referencing the results object,
>
> something like:
>
> <BEAN NAME="results" TYPE="com.mycompany.mypackage.MyObject" introspect="no"
> create="no" scope="request"></BEAN>
>
> and then you simply process the results within the JSP with code that might
> look like this:
>
> <%
> // Iterate through data
> int endPos = results.getSize();
> for (int i=1; i <= endPos; i++) {
> %>
>
> <p><%= results.getData(i) %>
>
> <%
> };
> %>
>
> And that's about it.
>
> Of course you can decide to call any JSP file you wish. Or you might just
> redirect to a page using
>
> resp.sendRedirect("mywebpage.html");
>
> One thing to remember is that you can't change the target frame/window of
> your servlet call. The target= in your HREF or Form action statement cannot
> be modified in your servlet (or at least I don't know of a way to do that).
>
> Anyway, I hope this helps. I rarely call a JSP directly given I usually
> need to populate it with a Bean I create on the fly.
>
> Cheers,
>
> Dan
>
> --
> Daniel Kirkdorffer
> Sr. Consultant, Syllogistics LLC
> Web: http://www.syllogistics.com/
> Email: [EMAIL PROTECTED]
>
> > ----------
> > From: Rich Nill[SMTP:[EMAIL PROTECTED]]
> > Reply To: Rich Nill
> > Sent: Wednesday, February 03, 1999 10:07 AM
> > To: [EMAIL PROTECTED]
> > Subject: JSP Access Models
> >
> > Hello -
> >
> > The JSP spec 0.92 describes 2 access models. In model 1, a request is
> > sent directly to JSP file. In model 2, a request is sent to a Servlet
> > which does the processing and then explicitly executes a JSP file.
> >
> > My question is, has anyone dealt with this second access model? If so,
> > could you share an example with me on how this is done. The examples
> > distributed with Sun's reference implementation of JSP seem to all use
> > access model 1.
> >
> > For example, our application contains a search engine. In this case,
> > we'll assume the search engine has the following web pages:
> >
> > - a "search" page which allows the user to enter search criteria
> > - a "list" page which displays a list of items which met the search
> > criteria
> > - a "detail" page which lists the details of one of the items
> >
> > The search engine is a drill down application. The user enters some
> > search criteria and presses "search". Here's the twist. If only one
> > item meets the search criteria, we should display the "detail" page for
> > this item. Otherwise, if more than one item meets the search criteria,
> > we should display the "list" page with all items which meet the
> > criteria. From the "list" page, a user can select a particular item to
> > get the "detail" page.
> >
> > Access model 2, as described in the JSP spec, seems to be a good fit for
> > the above problem.
> >
> > Thanks for the help,
> >
> > Rich Nill
> > Signal Internet Technologies, Inc.
> >
> > ==========================================================================
> > =
> > To unsubscribe, send email to [EMAIL PROTECTED] and include in the
> > body
> > of the message "signoff JSP-INTEREST". For general help, send email to
> > [EMAIL PROTECTED] and include in the body of the message "help".
> >
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JSP-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
>
> ===========================================================================
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff JSP-INTEREST". For general help, send email to
> [EMAIL PROTECTED] and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JSP-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".