File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

dynamically include HTML in JSP

 
Priyha Jootu
Ranch Hand
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic