Want new request on jsp:include

A

adamcrume

I have a servlet with a mapping like /myServlet/* which serves content
based on the URL. It works great when it gets called alone. However,
I also want to be able to include it in a jsp using <jsp:include
page="/myServlet/stuff"/>. The problem is that in that case the
servlet gets the request URL of the JSP, not itself, so it doesn't
know to serve up "stuff". Is there a way to do this purely using the
URL, without passing it parameters?
 
M

Manish Pandit

I have a servlet with a mapping like /myServlet/* which serves content
based on the URL. It works great when it gets called alone. However,
I also want to be able to include it in a jsp using <jsp:include
page="/myServlet/stuff"/>. The problem is that in that case the
servlet gets the request URL of the JSP, not itself, so it doesn't
know to serve up "stuff". Is there a way to do this purely using the
URL, without passing it parameters?


Instead of basing the actions on the URL, you might want to consider
using query-strings. So, myServlet can still be there, but instead of /
myServlet/getMeCoffee, the request URL will be more like /myServlet/
getMe?item=coffee.

This way, you an use include tag and pass parameters.

<jsp:include page="/myServlet/getMe">
<jsp:param name="item" value="coffee"/>
</jsp:include>

-cheers,
Manish
 
A

adamcrume

Instead of basing the actions on the URL, you might want to consider
using query-strings. So, myServlet can still be there, but instead of /
myServlet/getMeCoffee, the request URL will be more like /myServlet/
getMe?item=coffee.

This way, you an use include tag and pass parameters.

<jsp:include page="/myServlet/getMe">
<jsp:param name="item" value="coffee"/>
</jsp:include>

-cheers,
Manish

I had though about that, and it works, but it just feels like a hack
to me, rather than a solution. If it can't be done, perhaps it should
be chalked up to a limitation of the J2EE spec.

Thanks for your input, though.
 

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,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top