This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Struts and the fly likes Problem showing html:link in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Problem showing html:link in jsp" Watch "Problem showing html:link in jsp" New topic

Problem showing html:link in jsp

sumita mukherjee

Joined: Aug 27, 2007
Posts: 22

I am facing a problem with displaying the <html:link> tag in jsp. This is my jsp code:

<-- Taglib libraries defined here-->

<logic resent name="searchForm" property="results">
<%String xmldata=(String)request.getSession().getAttribute("xmlData"); %>
<%=xmldata %>
</logic resent>
This shows a html data sent from the Action class assigned to the variable �xmldata�.

In my Action class I do something like this (for testing):
public class searchaAction extends....{

xmldata=�<html:link action=\"\" styleId=\"vmgmt-leftmenuHREF\" title=\"\" target=\"basefrm\"> this is a link</html:link>�;
request.getSession().setAttribute("xmlData", data);

The issue is that the link is not shown in the main pane(only the text "this is a link" is shown as plain text).
However, the following code works fine:

public class searchaAction extends....{
xmldata=�<a href=�abc.html�>this is a link</a>�;

request.getSession().setAttribute("xmlData", data);

This link is shown correctly in the main pane.

I have all the taglibs added properly in the jsp.

Is there any special way to handle tags like �<html:Link>� when passed to the jsp as a html string, from action class?

Any pointer regarding this would really be much appreciated;

Thanks & regards,
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In order to understand why this won't work, let's review the JSP life cycle:
  • The JSP file is read by the JSP processor
  • Custom tags such as struts tags are interpreted and all JSP tags are converted to Java source code and compiled
  • The compiled code is executed. It is only at this point that your scriptlet actually executes and places the <html:link> tag in the output data stream along with the other html code.
  • So what's wrong with this picture? It's too late to put a Struts tag in the output stream. The custom tags were already interpreted much earlier in the life cycle. Solution: use a plain HTML <a> tag here, rather than a Struts html:link tag.

    Consultant, Sima Solutions
    I agree. Here's the link:
    subject: Problem showing html:link in jsp
    It's not a secret anymore!