File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Need clarification for jsp:include. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Need clarification for jsp:include." Watch "Need clarification for jsp:include." New topic
Author

Need clarification for jsp:include.

Anutosh Swamy
Ranch Hand

Joined: Sep 20, 2007
Posts: 30

Consider this two JSPs: -

Code for Page1.jsp (incldes Page2.jsp)

<HTML>
<BODY>
<FORM>
<TABLE>
<TR><TD>********</TD></TR>
</TABLE>
</FORM>
<jsp:include page="Page.jsp">
</BODY>
</HTML>


Code for Page2.jsp

<FORM>
<TABLE>
Some data coming from database
</TABLE>
</FORM>


When i did this and deployed my application and viewd Page1.jsp in the Internet Explorer I was able to see the contents of Page1.jsp and not Page2.jsp. However, when I viewed the page source of Page1.jsp from the browser it contains the source of Page2.jsp along with data coming from the database.

And now I had made a small change in Page1.jsp

Modified code for Page1.jsp (includes Page2.jsp)

<HTML>
<BODY>
<FORM>
<TABLE>
<TR><TD><jsp:include page="Page.jsp"></TD></TR>
</TABLE>
</FORM>
</BODY>
</HTML>


I got the display of Page2.jsp also.

Can any one explain what happened earlier?

K.Anutosh
---------------------------------------------------------------------------
SCJP 1.4


K. Anutosh<br /> <br />SCJP 1.4<br />SCWCD 1.4<br />OCA (Paper I)
Tarun Yadav
Ranch Hand

Joined: Sep 20, 2007
Posts: 134
I think the problem is with your HTML. If your code for the table was in fact just as you've shown, you might not get to see the data. That's probably why you could see it in the source but it wasn't rendered by the browser.

Remember, <table> should have <tr> and that should have <td> which should hold the actual data. Anywhere else, and you might see nothing!
Anutosh Swamy
Ranch Hand

Joined: Sep 20, 2007
Posts: 30

Dear Tarun,

The actual code of Page2.jsp is having a lots of <TR> and <TD> inside the table tag which is holding the data coming from database I just skipped it in this forum.

And, in Page1.jsp the code "<TR><TD>********</TD></TR>" is nothing but <TR><TD></TD></TR>, I just starred it because to attract the attaintion of the ranchers as I had kept <jsp:include> there to make Page1.jsp to display the contents of Page2.jsp.

and if you need some more clarification on the code, most welcome.

My question is:-

When I kept my <jsp:include> out of the </TD>,</TR>,</TABLE></FORM> in Page1.jsp I was not able to see the display of Page2.jsp although the source was included (what's wrong here?), but when I put <jsp:include> inside </TD>,</TR>,</TABLE></FORM> in Page1.jsp I got the display (Why not in the former case?)

K.Anutosh
---------------------------------------------------------------------------
SCJP 1.4
[ October 25, 2007: Message edited by: Anutosh Swamy ]
Tarun Yadav
Ranch Hand

Joined: Sep 20, 2007
Posts: 134
If you are able to view the expected source code but only have a problem with the display, that suggests that there is a problem rendering your page. Especially since you've only moved the <jsp:include> a little higher into some template text; it doesn't affect the execution in anyway.

I can't think of anything else. If you posted the actual code for page, ( without all your data of course, maybe only one or two rows ), that might help. Also, try viewing it with another browser, that might help see if this is actually the cause.
Anutosh Swamy
Ranch Hand

Joined: Sep 20, 2007
Posts: 30

Dear Tarun,

Thanks for the suggestion i'll try to run that application in another browser and I think that it will work.


K.Anutosh
---------------------------------------------------------------------------
SCJP 1.4
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need clarification for jsp:include.
 
Similar Threads
problem in including jsp file dynamically
Please solve the problem.
JSP returning old data, database was changed correctly!
Can't pass changed beans values from one JSP page to another
How to get jsp:param