PDA

Click to See Complete Forum and Search --> : dynamically change page content


Greyskull
Jul 5th, 2008, 04:06 AM
Hello,

Im starting to learn a few things with JSP and here is my current situation:
I have several jsp pages linked together namely: header, menu, content and footer.
Each item in the menu should be associated with a different content i.e menu1content.jsp, menu2content.jsp, etc...
I have created an ant files to build and compile the jsp pages to a .war file and run it using Tomcat.
The question is, how would i do it so that whenever a link is clicked on the menu, the content of the page dynamically changes. i.e when link 1 is clicked it automatically assigns menu1content.jsp to the page?

Here is my main layout (baselayout.jsp)


<%-- Include common set of tag library declarations for each layout --%>
<%@ include file="/WEB-INF/jsp/common/taglibs.jsp"%>

<html>
<head>
<title>
<tiles:getAsString name="title" ignore="true"/>
</title>
</head>

<body>
<div align="center">
<table width="80%%" border="0" cellpadding="5">
<tr>
<td colspan="2">
<tiles:insert attribute="header"/>
<hr />
</td>
</tr>
<tr>
<td rowspan="2" width="20%">
<tiles:insert attribute='menu' ignore="true"/>
</td>
<td width="80%"><tiles:insert attribute='content' ignore="true"/></td>
</tr>
<tr>
<td width="80%">
<hr />
<tiles:insert attribute="footer"/>
</td>
</tr>
</table>
</div>
</body>
</html>


im not sure whether ive explained this right but any help is gr8ly appreciated

Thanks,

ComputerJy
Jul 5th, 2008, 05:19 AM
use the <% %> tags to add add Java code to your page... Or read a little for more help ;)

Greyskull
Jul 5th, 2008, 05:55 AM
Thanks for the reply, i kinda knew i had to use the <% %> tags but not sure what to put inside it..anyways if it doesnt work how do i instead open another jsp page?

ive got the following set-up atm


<%@ include file="/WEB-INF/jsp/common/taglibs.jsp"%>

<div>
<ul>
<li>
<a href="http://localhost:8080/HelloWorldTile">Hello World</a>
</li>
<li>
link 2
</li>
</ul>
</div>


not sure what to put in link 2 which will open another jsp page which was compiled in the same war file unlike the first link which has a different war file..

thanks

ComputerJy
Jul 5th, 2008, 06:04 AM
you can use <% %> to write regular Java code.
Link 2 should be to were apache has mapped the web page, not the war file. War files are only containers (somewhat like jar files)