url and src path problems

Hi,

I have a web-app with the following structure.

- WebModule/mydirectory/jsp's

- src/mydirectory/servlets

The web.xml looks like this:

<servlet>

<servlet-name>servlet1</servlet-name>

<servlet-class>mydirectory.Servlet1</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>servlet1</servlet-name>

<url-pattern>/servlet1</url-pattern>

</servlet-mapping>

I have a form in a jsp which submits to one of my servlets. Because the jsp is inside a directory i must go one directory level back to access the servlet in the parent directory (form action="../servlet1?params=...").

This servlet will forward to another jsp, and since it uses a forward and not a sendRedirect, the last path in the url is the servlets path. This creates a problem with src paths in the next jsp since the path in the url is not relative to where the jsp is.

Now, there are a few solutions to this problem such as:

putting images, javascripts, css files in both the WebModule directory and mydirectory; putting absolute paths for all src's; etc.

But is there a way to make the url contain the full path to the servlet. Since the directory name that contains the servlets and the jsp's is the same, this would resolve my problem of src paths. To better illustrate what the url looks like:

start url: www.site.com/mydirectory/jsp1.jsp

--submit form to servlet1, which then forwards to jsp2.jsp

current url: www.site.com/servlet1?params=...

--jsp2.jsp cannot find src files since all are in WebModule/mydirectory/

is it possible to make the url look like this after submitting to the servlet:

www.site.com/mydirectory/servlet1?params=...

Hope this is understandable.

Thanks for any help.

[1926 byte] By [black_lotusa] at [2007-11-27 6:03:14]
# 1

You can't call the servlet in that way (form action="../servelt1?parm...")

The way for calling the servlet (in base your mapping) is

<form action="servlet1" method...>

and in the servlet, for taking the parameters, you must use

[Code]

String name= request.getParameter("name");

...

[/code]

The form parameters are sent by client user, no from your action.

Bye

PremierITAa at 2007-7-12 16:45:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Actually, calling it the way I stated works fine, but should I be using the servlet-name instead? And, actually I can still pass parameters through the url even though I am also passing form parameters. Thats not a problem.Thanks
black_lotusa at 2007-7-12 16:45:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3
Calling the servlet like <form action="serlvet1?..."> doesn't work at all actually. I can only access it by putting the relative path ../servlet1Why is that?
black_lotusa at 2007-7-12 16:45:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Is it just me or does it seem like there are fewer people using the servlet forum? It seems that just a few years ago this forum had dozens and dozens of post daily. Not the case anymore. What happened?
black_lotusa at 2007-7-12 16:45:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
dude...try doing thischange your url pattern to[code<url-pattern>/mydirectory/servlet1</url-pattern>[/code]i havent checked it... but think it works
subbu_javaa at 2007-7-12 16:45:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

Ya I tried that. Doesn't work. One question though, if I do it that way then my jsp form action should look like action="/mydirectory/servlet1", right?

Also, shouldn't I be able to access the servlet by directly calling:

www.host.com/mydirectory/servlet1

because that doesn't work. I get a page not found error. The only way to access the servlet is the original way that I posted - by going back one directory "../servlet1".

thanks

black_lotusa at 2007-7-12 16:45:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7
Actually got it to work the way you said. I was missing a forward slash.Thanks
black_lotusa at 2007-7-12 16:45:44 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...