Java Forum / General / May 2005
Struts link tag
GuyBrush Treepwood - 15 May 2005 03:09 GMT I want to use the <html:link> tag to make a link to a certain webpage. The URL of this page is a string that is stored in the database. So how would I specify this string in my tag? For request parameters, one can use the paramId, paramName and paramProperty attributes. But can the url itself also be manipulated this way?
 Signature "Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats." -- Howard Aiken
Amit Chatterjee - 15 May 2005 11:17 GMT > I want to use the <html:link> tag to make a link to a certain webpage. > The URL of this page is a string that is stored in the database. So how > would I specify this string in my tag? For request parameters, one can use > the paramId, paramName and paramProperty attributes. But can the url > itself also be manipulated this way? I am not sure if I understand this properly - you can use href or the page attribute to display web pages. You will have to read the value from the database and then store it is request scope, for example, and then
<html:link href="<%= (String)request.getAttribute(\"url\") %>" ..../>
The above solution using scriptlets is very ugly. If you are using struts-el:
<html:link href="${requestScope.url}" ..../>
Much better this time.
The best solution is to use JSTL tags for this purpose instead of Struts tag. Use the <c:url ...> tag instead.
The <html:link> tag is handy for defining forwards and actions otherwise JSTL tags are more flexible.
 Signature ********************************************************** * Amit Chatterjee amit.chatterjee AT quik-j DOT com * * http://www.quik-computing.com * * QUIK Computing - Home of the Open Source Contact Center* **********************************************************
GuyBrush Treepwood - 15 May 2005 23:30 GMT > The above solution using scriptlets is very ugly. If you are using > struts-el: [quoted text clipped - 8 lines] > The <html:link> tag is handy for defining forwards and actions otherwise > JSTL tags are more flexible. I already got a large portion of struts tags. Would it be bad to mix these JSTL tags with the already existing tags? I don't want to change all the tags because I'm running out of time. Maybe the struts-el is a better solution for me?
 Signature "Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats." -- Howard Aiken
Wendy S - 16 May 2005 00:13 GMT > I already got a large portion of struts tags. Would it be bad to mix these > JSTL tags with the already existing tags? I don't want to change all the > tags because I'm running out of time. Maybe the struts-el is a better > solution for me? Struts-EL is intended to be mixed with JSTL. If you look at the Struts-EL README file, it explains which JSTL tags you should use instead of the 'classic' Struts tags. For example, use <c:out> instead of <bean:write>.
 Signature Wendy
GuyBrush Treepwood - 16 May 2005 11:08 GMT > Struts-EL is intended to be mixed with JSTL. If you look at the Struts-EL > README file, it explains which JSTL tags you should use instead of the > 'classic' Struts tags. For example, use <c:out> instead of <bean:write>. Do I need all the jars listed at http://jakarta.apache.org/taglibs/doc/standard-1.0-doc/standard-1.0/GettingStart ed.html for using the jstl tag library? And where can I download a jar of the struts-el ? Can't seem to locate one.
 Signature "Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats." -- Howard Aiken
Amit Chatterjee - 16 May 2005 12:13 GMT >>Struts-EL is intended to be mixed with JSTL. If you look at the Struts-EL >>README file, it explains which JSTL tags you should use instead of the [quoted text clipped - 4 lines] > for using the jstl tag library? And where can I download a jar of the > struts-el ? Can't seem to locate one. For JSTL, you will need the jstl.jar. The rest will depend on your requirements. I suggest you follow the instruction closely to avoid any confusion.
Regarding Struts-el, the struts-el.jar is included with the Struts 1.2 distribution. Include the jar in the WEB-INF/lib. If you used the web.xml to define aliases for the struts tags using the <taglib> element, modify the references to point to the struts-el and you should be all set.
<taglib> <taglib-uri>/tags/struts-bean</taglib-uri> <taglib-location>/WEB-INF/struts-bean-el.tld</taglib-location> </taglib> <taglib> <taglib-uri>/tags/struts-html</taglib-uri> <taglib-location>/WEB-INF/struts-html-el.tld</taglib-location> </taglib> <taglib> <taglib-uri>/tags/struts-logic</taglib-uri> <taglib-location>/WEB-INF/struts-logic-el.tld</taglib-location> </taglib> <taglib> <taglib-uri>/tags/struts-nested</taglib-uri> <taglib-location>/WEB-INF/struts-nested.tld</taglib-location> </taglib> <taglib> <taglib-uri>/tags/struts-tiles</taglib-uri> <taglib-location>/WEB-INF/struts-tiles-el.tld</taglib-location> </taglib>
 Signature ********************************************************** * Amit Chatterjee amit.chatterjee AT quik-j DOT com * * http://www.quik-computing.com * * QUIK Computing - Home of the Open Source Contact Center* **********************************************************
Wendy Smoak - 16 May 2005 16:48 GMT > If you used the > web.xml to define aliases for the struts tags using the <taglib> > element, modify the references to point to the struts-el and you should > be all set. With a reasonably recent container, (Tomcat 4.1/Servlet 2.3) you no longer have to define the tld's in web.xml. The tld will be located inside the .jar file if you use the correct uri, for example:
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html-el" prefix="html-el" %>
 Signature Wendy
Amit Chatterjee - 17 May 2005 01:31 GMT >>If you used the >>web.xml to define aliases for the struts tags using the <taglib> [quoted text clipped - 7 lines] > <%@ taglib uri="http://jakarta.apache.org/struts/tags-html-el" > prefix="html-el" %> That is correct. However, I prefer to use the name <html:xxx> instead of <html-el:xxx> even if I am using the struts-el tags. This "-el" prefix can be tedious :).
 Signature ********************************************************** * Amit Chatterjee amit.chatterjee AT quik-j DOT com * * http://www.quik-computing.com * * QUIK Computing - Home of the Open Source Contact Center* **********************************************************
Amit Chatterjee - 16 May 2005 12:13 GMT >>Struts-EL is intended to be mixed with JSTL. If you look at the Struts-EL >>README file, it explains which JSTL tags you should use instead of the [quoted text clipped - 4 lines] > for using the jstl tag library? And where can I download a jar of the > struts-el ? Can't seem to locate one. For JSTL, you will need the jstl.jar. The rest will depend on your requirements. I suggest you follow the instruction closely to avoid any confusion.
Regarding Struts-el, the struts-el.jar is included with the Struts 1.2 distribution. Include the jar in the WEB-INF/lib. If you used the web.xml to define aliases for the struts tags using the <taglib> element, modify the references to point to the struts-el and you should be all set.
<taglib> <taglib-uri>/tags/struts-bean</taglib-uri> <taglib-location>/WEB-INF/struts-bean-el.tld</taglib-location> </taglib> <taglib> <taglib-uri>/tags/struts-html</taglib-uri> <taglib-location>/WEB-INF/struts-html-el.tld</taglib-location> </taglib> <taglib> <taglib-uri>/tags/struts-logic</taglib-uri> <taglib-location>/WEB-INF/struts-logic-el.tld</taglib-location> </taglib> <taglib> <taglib-uri>/tags/struts-nested</taglib-uri> <taglib-location>/WEB-INF/struts-nested.tld</taglib-location> </taglib> <taglib> <taglib-uri>/tags/struts-tiles</taglib-uri> <taglib-location>/WEB-INF/struts-tiles-el.tld</taglib-location> </taglib>
 Signature ********************************************************** * Amit Chatterjee amit.chatterjee AT quik-j DOT com * * http://www.quik-computing.com * * QUIK Computing - Home of the Open Source Contact Center* **********************************************************
Wendy Smoak - 16 May 2005 16:46 GMT > Do I need all the jars listed at http://jakarta.apache.org/taglibs/doc/standard-1.0-doc/standard-1.0/GettingStart ed.html
> for using the jstl tag library? And where can I download a jar of the > struts-el ? Can't seem to locate one. Look in your distribution of Struts. You don't say what version you're using, but it's probably under the 'contrib' directory. What I do is copy all the .jar files from the 'lib' directory of the distribution, then copy all the .jar files from contrib/struts-el/lib. That's everything you need.
http://struts.apache.org/userGuide/building_view.html#struts-el
http://struts.apache.org/faqs/struts-el.html
 Signature Wendy
GuyBrush Treepwood - 16 May 2005 17:58 GMT >> Do I need all the jars listed at >> [quoted text clipped - 10 lines] > > http://struts.apache.org/faqs/struts-el.html I used the library version of struts 1.2.4, but struts-el wasn't in there. It is in the binary download though. Thanks a lot for the help.
 Signature "Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats." -- Howard Aiken
GuyBrush Treepwood - 17 May 2005 16:23 GMT >> I want to use the <html:link> tag to make a link to a certain webpage. >> The URL of this page is a string that is stored in the database. So how [quoted text clipped - 8 lines] > > <html:link href="<%= (String)request.getAttribute(\"url\") %>" ..../>
> The above solution using scriptlets is very ugly. If you are using > struts-el: [quoted text clipped - 8 lines] > The <html:link> tag is handy for defining forwards and actions otherwise > JSTL tags are more flexible. The problem I have is: I can't use the ${...} because I use the Jakarta implementation of JSTL 1.0. If need the implementation of 2.0 to use the ${} expressions, but the Tomcat implementation I use is version 4.3, and it's not in my power to upgrade it.
It's probably the only place in my views where I would use a scriptlet. Has it other disadvantages besides being ugly?
 Signature "Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats." -- Howard Aiken
Wendy Smoak - 17 May 2005 16:45 GMT > The problem I have is: I can't use the ${...} because I use > the Jakarta implementation of JSTL 1.0. If need the implementation of 2.0 > to use the ${} expressions, but the Tomcat implementation I use is version > 4.3, and it's not in my power to upgrade it. That doesn't make sense. (Not least because there is no Tomcat 4.3.)
Can you post what you've tried that isn't working? I'm not sure why you think you can't use ${} expressions with JSTL 1.0.
The '2.0' you're referring to must be JSP 2.0 (not JSTL!). JSP 2.0 allows you to use expressions anywhere in the page.
 Signature Wendy
GuyBrush Treepwood - 17 May 2005 18:24 GMT >> The problem I have is: I can't use the ${...} because I use >> the Jakarta implementation of JSTL 1.0. If need the implementation of 2.0 >> to use the ${} expressions, but the Tomcat implementation I use is version >> 4.3, and it's not in my power to upgrade it. > > That doesn't make sense. (Not least because there is no Tomcat 4.3.) Sorry, Tomcat 4.1.3
> Can you post what you've tried that isn't working? I'm not sure why you > think you can't use ${} expressions with JSTL 1.0. <taglib> <taglib-uri>/c-rt</taglib-uri> <taglib-location>/WEB-INF/tld/c-rt.tld</taglib-location> </taglib>
<%@ taglib uri="/c-rt" prefix="c" %> <logic:present name="accountBean" scope="session"> <c:if test="${sessionScope.accountBean.authenticated != true}"> <html:link page="/service/signonForm.do">Sign On</html:link>| <html:link page="/service/newAccountForm.do">Register</html:link> </c:if> </logic:present>
I don't get any errors, but it just doesn't interpret the ${}. When I put this in the page:
<c:out value="${sessionScope.accountBean.username}", the ${} part is displayed literally the page.
> The '2.0' you're referring to must be JSP 2.0 (not JSTL!). JSP 2.0 > allows you to use expressions anywhere in the page. It indeed does. I misread this on the taglibs site. I now see my problem hasn't anything to do with versions. But what's the problem? I really can't see it.
 Signature "Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats." -- Howard Aiken
GuyBrush Treepwood - 17 May 2005 18:28 GMT >> Can you post what you've tried that isn't working? I'm not sure why you >> think you can't use ${} expressions with JSTL 1.0. [quoted text clipped - 11 lines] > </c:if> > </logic:present> Of course I also included the struts-el taglibs.
 Signature "Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats." -- Howard Aiken
Wendy Smoak - 17 May 2005 18:54 GMT > <taglib> > <taglib-uri>/c-rt</taglib-uri> > <taglib-location>/WEB-INF/tld/c-rt.tld</taglib-location> > </taglib> No wonder! You're using the 'rt' version of the taglib, which doesn't recognize expressions.
Here's a mailing list thread which should be helpful: http://www.mail-archive.com/struts-user@jakarta.apache.org/msg49488.html
Suggestion, get rid of the "loose" tlds under WEB-INF, remove the <taglib> tags from web.xml, and use this in the JSP: <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
Similarly with Struts-EL, for example: <%@ taglib uri="http://struts.apache.org/tags-html-el" prefix="html-el" %>
Your expressions should start working if you use the 'regular' version of JSTL.
 Signature Wendy Smoak
GuyBrush Treepwood - 18 May 2005 01:56 GMT >> <taglib> >> <taglib-uri>/c-rt</taglib-uri> [quoted text clipped - 18 lines] > Your expressions should start working if you use the 'regular' version of > JSTL. I did as you told me, and everything seemed to work. But now, I want to set a security constraint so users cannot access .jsp pages directly, except for the /index.jsp. All the other files are in subdirectories, so:
<security-constraint> <web-resource-collection> <web-resource-name>no_access</web-resource-name> <url-pattern>/*/*.jsp</url-pattern> </web-resource-collection> <auth-constraint/> </security-constraint>
However, if I want to test this by going to:
http://blabladomain/bookmarks/Folder.jsp
I get following error:
org.apache.jasper.JasperException: /bookmarks/Folder.jsp(0,0) This absolute uri (http://java.sun.com/jstl/core) cannot be resolved in either web.xml or the jar files deployed with this application
 Signature "Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats." -- Howard Aiken
Wendy S - 18 May 2005 06:22 GMT > I did as you told me, and everything seemed to work. But now, I want to > set a security constraint so users cannot access .jsp pages directly, [quoted text clipped - 15 lines] > absolute uri (http://java.sun.com/jstl/core) cannot be resolved in either > web.xml or the jar files deployed with this application One thing at a time! Does the page work *without* the security constraint? (What does 'everything seemed to work' mean? Were you getting expressions evaluated, or not?)
The error message says it can't find the tld. Look in all the .jar files you've got and make sure that there is a tld with that uri in it. It's in standard.jar on my system, and the filename is c.tld. Make sure you have exactly one of these.
(To look inside jar files, you can do jar -tvf filename.jar and it will print out the contents.)
You're on Tomcat 4.1, right? It _should_ work, but you can always go back to mapping the tlds in web.xml while you work out the rest of the issues.
On to your security constraint. The URL you are using for your security constraint is wrong. Read SRV.11.2 of the Servlet Specification-- it's not a regular expression, it's a pattern with some specific, very limited rules. There are only three patterns that it recognizes, anything else is an exact match.
http://java.sun.com/products/servlet/reference/api/index.html#specs (Get version 2.3 for Tomcat 4.1)
 Signature Wendy
GuyBrush Treepwood - 18 May 2005 12:08 GMT >> I did as you told me, and everything seemed to work. But now, I want to >> set a security constraint so users cannot access .jsp pages directly, [quoted text clipped - 19 lines] > (What does 'everything seemed to work' mean? Were you getting expressions > evaluated, or not?) Yes, my expressions were evaluated and I did not get the same error as with the security constraint.
> The error message says it can't find the tld. Look in all the .jar files > you've got and make sure that there is a tld with that uri in it. It's in > standard.jar on my system, and the filename is c.tld. Make sure you have > exactly one of these. Yes, it is present.
> You're on Tomcat 4.1, right? It _should_ work, but you can always go back > to mapping the tlds in web.xml while you work out the rest of the issues. [quoted text clipped - 7 lines] > http://java.sun.com/products/servlet/reference/api/index.html#specs (Get > version 2.3 for Tomcat 4.1) Because I don't get the error without the security constraint, it must be because of the wrong URL pattern.
 Signature "Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats." -- Howard Aiken
Amit Chatterjee - 18 May 2005 12:40 GMT Try with
<url-pattern>*.jsp</url-pattern>
instead of
<url-pattern>/*/*.jsp</url-pattern>
>>>I did as you told me, and everything seemed to work. But now, I want to >>>set a security constraint so users cannot access .jsp pages directly, [quoted text clipped - 44 lines] > Because I don't get the error without the security constraint, it must be > because of the wrong URL pattern.
 Signature ********************************************************** * Amit Chatterjee amit.chatterjee AT quik-j DOT com * * http://www.quik-computing.com * * QUIK Computing - Home of the Open Source Contact Center* **********************************************************
GuyBrush Treepwood - 18 May 2005 14:41 GMT >>> However, if I want to test this by going to: >>> http://blabladomain/bookmarks/Folder.jsp [quoted text clipped - 3 lines] >>> absolute uri (http://java.sun.com/jstl/core) cannot be resolved in either >>> web.xml or the jar files deployed with this application
>> On to your security constraint. The URL you are using for your security >> constraint is wrong. Read SRV.11.2 of the Servlet Specification-- it's not [quoted text clipped - 7 lines] > Because I don't get the error without the security constraint, it must be > because of the wrong URL pattern. I keep getting the same errors even with:
<security-constraint> <web-resource-collection> <web-resource-name>no_access</web-resource-name> <url-pattern>*.jsp</url-pattern> </web-resource-collection> <auth-constraint/> </security-constraint>
The strange thing, I don't get it with all pages although the same IncludeTop.jsp (where the taglibs are included) is included in all the jsp pages.
 Signature "Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats." -- Howard Aiken
Wendy S - 18 May 2005 15:50 GMT > The strange thing, I don't get it with all pages although the same > IncludeTop.jsp (where the taglibs are included) is included in all the jsp > pages. Please post the include statement you're using. Is it compile time, or runtime? (See where I'm going with this? It's like changing a static final constant in Class B... the in general compiler will not be able to tell that Class A, which uses that constant, needs to be recompiled.)
Shut down Tomcat and delete everything in the 'work' directory for this webapp. Then restart and see what happens.
What it has to do with the security constraint, I have NO idea! I think you've got other problems, but this may be masking some more consistent behavior that will help you figure it out.
 Signature Wendy
GuyBrush Treepwood - 18 May 2005 17:01 GMT >> The strange thing, I don't get it with all pages although the same >> IncludeTop.jsp (where the taglibs are included) is included in all the jsp [quoted text clipped - 4 lines] > final constant in Class B... the in general compiler will not be able to > tell that Class A, which uses that constant, needs to be recompiled.) <%@page contentType="text/html"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> <%@ taglib uri="http://struts.apache.org/tags-html-el" prefix="html-el" %> <%@ taglib uri="http://struts.apache.org/tags-logic-el" prefix="logic-el" %> <%@ taglib uri="http://struts.apache.org/tags-bean-el" prefix="bean-el" %>
 Signature "Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats." -- Howard Aiken
GuyBrush Treepwood - 18 May 2005 17:44 GMT >> Please post the include statement you're using. Is it compile time, or >> runtime? (See where I'm going with this? It's like changing a static [quoted text clipped - 7 lines] > <%@ taglib uri="http://struts.apache.org/tags-logic-el" prefix="logic-el" %> > <%@ taglib uri="http://struts.apache.org/tags-bean-el" prefix="bean-el" %> This is in the file common/IncludeTop.jsp
And the include statement in the file that gives the error is:
<%@include file="../common/IncludeTop.jsp"%>
 Signature "Don't worry about people stealing your ideas. If your ideas are any good, you'll have to ram them down people's throats." -- Howard Aiken
Wendy Smoak - 18 May 2005 18:16 GMT "GuyBrush Treepwood" <spambak@hotmail.com> wrote>
> And the include statement in the file that gives the error is: > > <%@include file="../common/IncludeTop.jsp"%> This is a compile-time, static include. http://java.sun.com/products/jsp/syntax/1.1/syntaxref117.html
Did deleting the work files help at all? I doubt that Tomcat will recompile if you change an included file, though I haven't tested it. Try putting the <%@ taglib ...> tags directly in the JSP.
 Signature Wendy
Free MagazinesGet these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...
|
|
|