c:url and html:base

Hello

I cant seem to get the browser to render an html img tag using jstl. I expected that using the base tag and the relative address of the servlet is all that is necessary. The servlet is never called. Can someone help understand how to properly structure this? tia.

<c:url value="/myFirstServlet" var="myURL">

<c:param name="param1" value="${sessionScope.forServelet}"/>

</c:url>

here is the jsp

<head>

<base href="http://www.domain.com"> </head>

<table border="1" cellspacing="0" cellpadding="0">

<tr>

<td></td>

<td><img src="${dynaAd}" alt="" /></td>

</tr>

</table>

here is the output

<table border="1" cellspacing="0" cellpadding="0">

<tr>

<td></td>

<td><img src="/context/myFirstServlet?param1=123"></td>

</tr>

</table>

myFirstServlet never gets called.

[1043 byte] By [aster_bodya] at [2007-11-27 6:39:35]
# 1

What is the URL of the servlet as configured in the servlet-mapping of your web.xml file?

The <c:url> tag is generating an absolute reference from the root of your web server into a web application called "context". As such the base tag is irrelevant. It only applies to urls with relative links - ie that do not start with /.

Is the generated URL correct? If not what is wrong with it?

evnafetsa at 2007-7-12 18:08:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Hello

Thanks. The generated url should be a concatenation of the base and the c:url output. I thought the browser would do that automatically. What is the proper programmatic way to get the url to be/or have the browser execute for the img tag and render http://www.domain.com/context/myFirstServlet?param1=123

aster_bodya at 2007-7-12 18:08:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

The link /context/myFirstServlet will look on the same server as generated the JSP page. Is that http://www.domain.com? ie what url do you use to access the jsp page with the image on it?

The base href is used as a base for resolving page relative links only - links that do not start with /. / indicates to the browser go to the root of the server that you retrieved the page from and resolve from there.

Website relative link: /context/images/myImage.jpg - looks starting at the server root

As opposed to context/images/myImage.jpg - without the starting slash it looks either from the "base" url (if specified) or the url from which the current page was served.

Does that help?

evnafetsa at 2007-7-12 18:08:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4

> The link /context/myFirstServlet will look on the

> same server as generated the JSP page. Is that

> http://www.domain.com? ie what url do you use to

> access the jsp page with the image on it?

>

The jsp is forwarded from an action. When I tried just the html:base it made the base be the full url up to the that action. I assumed that is why it was never executing myFirstServlet. Yes, the on http://www.domain.com I have modjk working to pass *.jsp and *.do on to tomcat. What I need to do is to properly format that img tag in the jsp to be able to access the context/myFirstServlet

> The base href is used as a base for resolving page

> relative links only - links that do not start

> with /. / indicates to the browser go to the root of

> the server that you retrieved the page from and

> resolve from there.

>

Okay then can I just make the syntax on the c:url be ../ and make the base be http://www.domain.com/context

> Website relative link: /context/images/myImage.jpg -

> looks starting at the server root

> As opposed to context/images/myImage.jpg - without

> the starting slash it looks either from the "base"

> url (if specified) or the url from which the current

> page was served.

>

I cant use the use the current page that served, because of above. I tried making the base www.domain.com/ and the c:url as context/myFirstServlet and that didnt work. What am I missing? I know the servlet works, it works from localhost perfectly. I know the browser is not executing the servlet, but jstl is properly parameterizing it. I am doing this as a raw html img tag. I will try it with the struts img tag. Any other ideas? tia

> Does that help?

aster_bodya at 2007-7-12 18:08:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5

> on http://www.domain.com I have modjk working to pass *.jsp and *.do on to tomcat.

Oh you have apache in front of this?

Is apache installed on your localhost as well?

Do you have a URL you can type into your browser that retrieves the correct image?

What would apache do to the Servlet call? It doesn't have .jsp or .do in it so it wouldn't pass it on to Tomcat? That would explain the image not showing up right?

evnafetsa at 2007-7-12 18:08:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Hello

Apache just passes it through with modjk configuration. and passes it onto Tomcat It works fine with other sites. Actually on my other sites I am sending content directly opening a stream with the browser. This is the first time I am using a jsp that has an embedded servlet call that will render an image into the tag. However that should work, correct? I cant get the syntax right or maybe I really need Struts.

I just tried it with the jstl and crudely put in the entire url http://www.domain.com/context/myFirstServlet . It rendered it in the img tag as http://www.domain.com/context/myFirstServlet?param1=123 . But did not render the content. Ideas?

aster_bodya at 2007-7-12 18:08:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...