aspose file tools*
The moose likes JSP and the fly likes dynamically include HTML in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "dynamically include HTML in JSP" Watch "dynamically include HTML in JSP" New topic
Author

dynamically include HTML in JSP

Priyha Jootu
Ranch Hand

Joined: Sep 13, 2001
Posts: 47
Hi,
I want to check the user and depending on the user, different page has to be included.
Her is the part of code :
<%
if (user_id.equals("prthir"))
<%@ include file = "/sps/rhs.html" %>
else
<%@ include file = "/sps/prthir_rhs.html"%>
%>
i don't know why some errors come out, is there any syntax problem? even if i use <jsp:include tag, its not working, let me know how to include html dynamically

Thanks
priyha
kavitha rama
Ranch Hand

Joined: Jun 18, 2003
Posts: 38
Syntax is right but there are 2 includes, <%@ -- %> is used for static includes and <jsp:include --> is used for dynamic includes. So when you use <jsp:include > include file should be a complete file, it should be executed by itself, not just a part of original file
and also post errors
kavitha rama
Ranch Hand

Joined: Jun 18, 2003
Posts: 38
Syntax is wrong. It should be as follows
<%if (user_id.equals("prthir"))%>
<%@ include file = "/sps/rhs.html" %>
<%else%>
<%@ include file = "/sps/prthir_rhs.html"%>
Since include tag is already in<% -%>
Hope this helps u
Priyha Jootu
Ranch Hand

Joined: Sep 13, 2001
Posts: 47
I tried with what you said, still not working, it is saying an error: 'else' without 'if'.
I think we need to put all the if-else code inside one <% ... %>
I am not including a fully independent file there, just a part - the right hand side column of the page. basically i want to re use the lefside column and right side column in all my jsp's. these colums are just html files with links in it.
please let me know if you know any other way of doing this dynamically substituting the html files.
Thanks
priyha
Priyha Jootu
Ranch Hand

Joined: Sep 13, 2001
Posts: 47
I tried the following code and now it works!!
The paranthesis was missing and thats the problem.
<%
String sidebar;
String user_id = "prthir";
if (user_id.equals("prthir"))
{
%>
<%@ include file = "/sps/rhs.html" %>
<%
}
else
{
%>
<%@ include file = "/sps/prthir_rhs.html" %>
<%
}
%>

Thanks,
priyha
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: dynamically include HTML in JSP
 
Similar Threads
How can I include a file(.html) in jsp dynamically.
JSP Include tag problem
how to include frame page inside jsp
Help on dynamically Including html files in JSP
Include dynamic HTML in a JSP