Struts link tag

G

GuyBrush Treepwood

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?
 
A

Amit Chatterjee

GuyBrush said:
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.

--
**********************************************************
* Amit Chatterjee amit.chatterjee AT quik-j DOT com *
* http://www.quik-computing.com *
* QUIK Computing - Home of the Open Source Contact Center*
**********************************************************
 
G

GuyBrush Treepwood

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.

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?
 
W

Wendy S

GuyBrush Treepwood said:
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:eek:ut> instead of <bean:write>.
 
G

GuyBrush Treepwood

A

Amit Chatterjee

GuyBrush said:
Do I need all the jars listed at
http://jakarta.apache.org/taglibs/doc/standard-1.0-doc/standard-1.0/GettingStarted.html
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>


--
**********************************************************
* Amit Chatterjee amit.chatterjee AT quik-j DOT com *
* http://www.quik-computing.com *
* QUIK Computing - Home of the Open Source Contact Center*
**********************************************************
 
A

Amit Chatterjee

GuyBrush said:
Do I need all the jars listed at
http://jakarta.apache.org/taglibs/doc/standard-1.0-doc/standard-1.0/GettingStarted.html
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>


--
**********************************************************
* Amit Chatterjee amit.chatterjee AT quik-j DOT com *
* http://www.quik-computing.com *
* QUIK Computing - Home of the Open Source Contact Center*
**********************************************************
 
W

Wendy Smoak

GuyBrush Treepwood said:
Do I need all the jars listed at
http://jakarta.apache.org/taglibs/doc/standard-1.0-doc/standard-1.0/GettingStarted.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
 
W

Wendy Smoak

Amit Chatterjee said:
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" %>
 
G

GuyBrush Treepwood

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

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.
 
A

Amit Chatterjee

Wendy said:
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" %>

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 :).



--
**********************************************************
* Amit Chatterjee amit.chatterjee AT quik-j DOT com *
* http://www.quik-computing.com *
* QUIK Computing - Home of the Open Source Contact Center*
**********************************************************
 
G

GuyBrush Treepwood

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.

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?
 
W

Wendy Smoak

GuyBrush Treepwood said:
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.
 
G

GuyBrush Treepwood

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:eek:ut 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.
 
G

GuyBrush Treepwood

<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>

Of course I also included the struts-el taglibs.
 
W

Wendy Smoak

GuyBrush Treepwood said:
<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/[email protected]/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.
 
G

GuyBrush Treepwood

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/[email protected]/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.

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
 
W

Wendy S

GuyBrush Treepwood said:
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

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)
 
G

GuyBrush Treepwood

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?)

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.

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)

Because I don't get the error without the security constraint, it must be
because of the wrong URL pattern.
 
A

Amit Chatterjee

Try with

<url-pattern>*.jsp</url-pattern>

instead of

<url-pattern>/*/*.jsp</url-pattern>


GuyBrush said:
Yes, my expressions were evaluated and I did not get the same error as
with the security constraint.




Yes, it is present.




Because I don't get the error without the security constraint, it must be
because of the wrong URL pattern.


--
**********************************************************
* Amit Chatterjee amit.chatterjee AT quik-j DOT com *
* http://www.quik-computing.com *
* QUIK Computing - Home of the Open Source Contact Center*
**********************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top