tags:

views:

61

answers:

4

when developing locally, does it make a difference if the context is '/' or '/appname/' ?

Assuming you will be deploying to http://www.example.com

I like it when my local url is:

http://localhost:8080/

but just want to know if the url is

http://localhost:8080/appname/

if it makes any difference?

+2  A: 

You can use HttpServletRequest.getContextPath() to figure out where the app is deployed at runtime so in theory it's possible.

In practice nobody does this and the context path is assumed in links, images, form actions, etc.

cletus
so your saying, in practice, people develop locally using / or /appname ?
Blankman
@Blankman I usually develop locally to the same context root used in production, which is (99% of the time) `/`.
cletus
I'll object to "nobody does this" - every webapp my company produces uses macros for generating urls which under the cover use getContextPath()
matt b
@matt: you're in a pretty small minority then.
cletus
@cletus: that would be a pretty big assumption...
Nate
@cletus I try to encourage the best practice :)
matt b
+1  A: 

If you're deploying on the root, then the HttpServletRequest#getContextPath() will always resolve to /.

Your interest is the pathinfo. In a Filter you can reveal it by HttpServletRequest#getRequestURI() and in a Servlet also by HttpServletRequest#getPathInfo().

BalusC
+1  A: 

I would say if you're planning to deploy with Apache (or something else that handles the initial HTTP request) in front of your app server (tomcat?), it doesn't matter: Apache config will sort that aspect out.

If you plan to go with just your app server in production, no HTTP server in front of it, I would say it does matter, as you want to make sure your app's available at www.example.com, not example.com/appname.

By "does matter" I mean there's inherently some value in having your local server configuration the same as the production one to reduce nasty surprises in the future; you can of course configure local differently to production.

You also need to bear in mind: will you have multiple Java webapps running under a single app server? If so, plan for how you'll deploy those in production.

Brian
+1  A: 

you need to be careful using the root context as there is the possibility when coding to assume you are in the root context and result in a webapp that will only run in the root context. By using a named context you avoid this possibility.

objects