• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

servlet to JSP to HTML to JSP

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been doing a lot of reading, but I want to make sure what i am thinking is possible. I have a servlet that instantiates a bean, and then forwards control on to a JSP. I am using:
req.setAttribute("RequestBean", rqBean);
RequestDispatcher dispatcher =
getSevletContext().getRequestDispatcher("main.jsp");
dispatcher.forward(request, response);
Now in main.jsp, as long as I use <jsp:usebean id="RequestBean" I have the same instance of the bean and can use the get and set property methods accordingly to get the information that was put there by the servlet, correct?
Now this JSP will include one of 8 different HTML files, depending on some predefined criteria (if criteria1 then include file1.html, if criteria2 then include file2.html, etc...). The HTML files are basically different arrangements of HTML Framesets and Frames. The <src attribute on the frames in the HTML files I want to be another JSP file, like:
<FRAME src="frame.jsp?quadrant="1">
Now can I still access my original bean okay in this new jsp if I use the same <JSP:usebean id="RequestBean" in the frame.jsp? And can I then get my quadrant parameter from the response object created by frame.jsp?
Lastly, will calling a JSP (from a servlet), with that JSP including an HTML file that uses another JSP page actually come together and work and create the page that I need, that is, a page of various frames, with each frame holding different dynamic content based on the last JSP and the bean I am using.
Hopefully that was clear. If anyone could let me know if this design will work and possibly provide some hints/ideas I would greatly appreciate it.
Thanks in advance
Brian
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am still having trouble referencing session information in the final .jsp that I am using. I successfully instantiated a bean in my initial servlet, passed it to my first .JSP where I extracted a value for the number of frames the page to be displayed would need.
<%@ page language="java" %>
<jsp:useBean id="RequestBean" scope="request" type="RequestBean" />
<%
int numFrames = RequestBean.getNumFrames();
double randomDbl = Math.random() * numFrames;
int randomFrame = (int)Math.ceil(randomDbl);
String file = "/frame0" + numFrames + "_" + randomFrame + ".htm";
%>
<HTML>
<HEAD>
<TITLE>Main JSP</TITLE></HEAD>
<jsp:include page="<%=file %>" flush="true" />
</HTML>
I got that .JSP to correctly include the right HTML file, and I could even reference the request variables passed along via the <src tag in that HTML, ie:
<frame name="Frame1" src="/frame.jsp?frame=1">
and in the .jsp:
<%
int numFrame = Integer.parseInt(request.getParameter("frame") );
%>
<HTML>
<HEAD>
<TITLE>Generic Frame Loader- JSP</TITLE></HEAD>
<%=numFrame%>
</HTML>
But I still need to access information out of the bean that the servlet created. I tried changing everything to sessions, ie. the servlet stored information I needed using session.putValue()
and then trying to use session.getValue() in the final JSP but that did not work either, I always get null. Is the html page that is loading the JSP page creating a new session because of the frames? or do I need to change the bean to a EJB? Any ideas would be greatly appreciated!
Thanks
Brian
 
reply
    Bookmark Topic Watch Topic
  • New Topic