File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes url-pattern problem on production server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "url-pattern problem on production server" Watch "url-pattern problem on production server" New topic
Author

url-pattern problem on production server

Vijayender Bandaru
Greenhorn

Joined: Nov 21, 2006
Posts: 21
We have ran into a problem when we tried to deploy our webapp on production server.

In our web.xml,we configured all the servlets with url-pattern of the format and we referred the servlet with this url-pattern throughout the application at numerous locations.The application worked fine on dev. server but when deployed on prod. server,due to its virtual mapping it expects /servlet before the servlet name as in

when referring to a servlet in the jsp page.

I am wondering whether this can be possible without making any changes to the jsp pages.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I recommend that you get your dev environment to match your production environment. If you know it's going to require the '/servlet' prefix, when you publish it the develop it with the same requirement.

Why the difference?
Are you using different containers for dev and production?
Are you using a combination of webserver + connector + container in your production environment?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Chris Corbyn
Ranch Hand

Joined: Jan 14, 2007
Posts: 114
You just need to set the context-path for your application to be "" (empty). The /servlet context is a special tomcat feature allowing you to run servlets by name.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Chris Corbyn:
You just need to set the context-path for your application to be "" (empty). The /servlet context is a special tomcat feature allowing you to run servlets by name.


Without knowing more about the original poster's production environment, we can't really say that for sure.

The '/servlet' prefix might be a mapping set up in the connector between the webserver and application server. In fact, we don't even know if the original poster is using Tomcat.
This is why I asked for clarification before trying to recommend a specific solution.
Chris Corbyn
Ranch Hand

Joined: Jan 14, 2007
Posts: 114
Quite true, my bad.
Vijayender Bandaru
Greenhorn

Joined: Nov 21, 2006
Posts: 21
Our production server (javaservlethosting.com) is on virtual hosting environment.We dont have access to modify server configuration (server.xml and other configuration files).Whatever we can do,we can do at application level.

This is an excerpt from the production server deployment documentation saying how to access servlets.

The servlets will be accessed, however, through the URL
(via a virtual mapping): http://www.xyzhostname.com/servlet/MyServlet
Note that 'MyServlet' is the actual name of your servlet, it is not a
directory.



all servlets are mapped as follows:



is it possible to call the servlets as



without making any changes to jsp files where the servlets are referred as /someServlet.

---------------------------------------
OR
to be more specific its also OK if all the incoming requests of the pattern:

" target="_blank">http://www.xyzhostname.com/antiBotServlet[/CODE]

be mapped to :

" target="_blank">http://www.xyzhostname.com/servlet/antiBotServlet[/CODE]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Most hosting companies that offer Java hosting do so with a combination of the Apache Web Server and a container such as Tomcat or Resin.
When they do this, they have to configure a properties file and set up the URL patterns that will be mapped to the servlet container. It's common to use
/servlet/* and *.jsp.

You should find out what they're doing and set up your development machines the same way. If you can't do this, you should, at least, try to set up a QA machine with the same settings so you can test your code in an identical environment before promoting to the production box.

If you can't get the two to match, you might need to keep two copies of your deployment descriptor (one with the /servlet/ mapping for production and one without for development.
You could also set up a context-init-param to represent the prefix and use that to build your links in the JSPs.

<c:set var="prefix" value="${thePrefix}" />
<form action="${thePrefix}/someServlet" method.....>

Set the prefix to be "" in dev and "/servlet" in production.

If this sounds cumbersome and error prone, give some serious thought to my first suggestion and set up the dev environment to match the production one.
Vijayender Bandaru
Greenhorn

Joined: Nov 21, 2006
Posts: 21

[ September 16, 2007: Message edited by: Vijayender R. Bandaru ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: url-pattern problem on production server