aspose file tools*
The moose likes Servlets and the fly likes servlet to JSP to HTML to JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "servlet to JSP to HTML to JSP" Watch "servlet to JSP to HTML to JSP" New topic
Author

servlet to JSP to HTML to JSP

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Nov 22, 2008
Posts: 18944
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: servlet to JSP to HTML to JSP