Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #4498

Re: Dealing with application names in a JEE web app

From Arved Sandstrom <asandstrom3minus1@eastlink.ca>
Newsgroups comp.lang.java.programmer
Subject Re: Dealing with application names in a JEE web app
References <irebhd$16t$1@dont-email.me>
Message-ID <mPACp.8269$eb4.4823@newsfe02.iad> (permalink)
Organization Public Usenet Newsgroup Access
Date 2011-05-23 19:01 -0300

Show all headers | View raw


On 11-05-23 04:11 PM, markspace wrote:
> Hi all,
> 
> I'm delving more heavily into JSP/Servlets and JSF at the moment.  I've
> found something that looks like a questionable design issue by the JEE
> folks at Sun (now Oracle, of course) and I'd like to pick your brains
> about how you might deal with it.
> 
> Basically, when developing a JEE web app, the application name gets
> inserted into every URL and associated path.  If my app is named
> TechDarwinia, for example, then all URLS look like this:
> 
> http://localhost:8080/TechDarwinia/
> http://localhost:8080/TechDarwinia/faces/readPost.xhtml
> http://localhost:8080/TechDarwinia/rsrc/css/style.css
> 
> The problem is of course that the web app could be renamed anything by
> the deployer/sysop, and I've got strings hard coded to that app name
> TechDarwinia.
> 
> So how do folks write their apps so that they can handle being deployed
> under different names?
[ SNIP ]

That "application name" is simply the web context root. A J2EE/Java EE
application server can host more than one web application, and that
context root in the request URLs is how the app server knows how to pass
the request to Web App A and not Web App B.

You (anyone in the ops chain) have complete control over what the web
context root is, in the application.xml.

With respect to your complaint about relative URLs, in response to Lew's
suggestion to that effect, I don't think *any* system handles arbitrary
movement of web resources (HTML, JSP, XHTML etc). Regardless of how a
controller parses the resource path described by the URL (URL parts
corresponding to directories in a filesystem hierarchy, or something
different like grabbing resources out of a DB) there still has to be a
definite mapping. This isn't even a J2EE/Java EE thing: it's a web app
thing right across the board.

For your other problem, since the resource locations aren't changing,
and you are using Faces (Facelets), you have access to JSF EL implicit
objects. In a situation like this I use (off the top of my head)

#{facesContext.externalContext.requestContextPath}

so for example

#{facesContext.externalContext.requestContextPath}/rsrc/css/style.css

AHS

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

Dealing with application names in a JEE web app markspace <-@.> - 2011-05-23 12:11 -0700
  Re: Dealing with application names in a JEE web app Lew <noone@lewscanon.com> - 2011-05-23 15:30 -0400
    Re: Dealing with application names in a JEE web app markspace <-@.> - 2011-05-23 12:41 -0700
    Re: Dealing with application names in a JEE web app markspace <-@.> - 2011-05-23 13:10 -0700
      Re: Dealing with application names in a JEE web app Lew <noone@lewscanon.com> - 2011-05-23 17:02 -0400
        Re: Dealing with application names in a JEE web app jebblue <n@n.nnn> - 2011-05-23 19:30 -0500
          Re: Dealing with application names in a JEE web app Lew <noone@lewscanon.com> - 2011-05-23 21:13 -0400
        Re: Dealing with application names in a JEE web app markspace <-@.> - 2011-05-24 09:32 -0700
  Re: Dealing with application names in a JEE web app Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-05-23 19:01 -0300
  Re: Dealing with application names in a JEE web app Owen Jacobson <angrybaldguy@gmail.com> - 2011-05-23 23:20 -0400
  Re: Dealing with application names in a JEE web app Tom Anderson <twic@urchin.earth.li> - 2011-05-24 18:16 +0100
    Re: Dealing with application names in a JEE web app markspace <-@.> - 2011-05-25 12:16 -0700
      Re: Dealing with application names in a JEE web app markspace <-@.> - 2011-05-25 16:40 -0700
      Re: Dealing with application names in a JEE web app Tom Anderson <twic@urchin.earth.li> - 2011-05-26 18:07 +0100
        Re: Dealing with application names in a JEE web app Lew <noone@lewscanon.com> - 2011-05-26 13:25 -0400
          Re: Dealing with application names in a JEE web app markspace <-@.> - 2011-05-26 12:57 -0700
            Re: Dealing with application names in a JEE web app Lew <noone@lewscanon.com> - 2011-05-26 19:39 -0400
              Re: Dealing with application names in a JEE web app Arved Sandstrom <asandstrom3minus1@eastlink.ca> - 2011-05-27 07:31 -0300
                Re: Dealing with application names in a JEE web app Lew <noone@lewscanon.com> - 2011-05-27 10:14 -0400
        Re: Dealing with application names in a JEE web app markspace <-@.> - 2011-05-26 12:51 -0700
        Re: Dealing with application names in a JEE web app Steve Sobol <sjsobol@JustThe.net> - 2011-05-26 14:51 -0700

csiph-web