Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » Cannot set context root to "/"
Cannot set context root to "/" [message #169224] Fri, 12 May 2006 11:17 Go to next message
Luis is currently offline LuisFriend
Messages: 20
Registered: July 2009
Junior Member
Hello,

I am using WTP 1.0.2.v200604280000, the "all in one" version that comes
with Eclipse 3.1.2. I use Tomcat 5.5.17 as the server.

I see I can change the context root of a web project by editing the
project properties and then selecting the J2EE section, and it works
perfectly well.

But if I set the context root to "/", it simply does not work, and Tomcat
returns a typical 404 error message: " The requested resource (/) is not
available".

Maybe this error has to do with the fact that Tomcat assumes that "" and
not "/" is the way to identify a context root as the server root path,
e.g.:

<Host name="myservername.com" appBase="c:/Web">
<Context path="" docBase="MyWebBase" />
</Host>

The problem then is that WTP does not allow me to provide an empty String
as the context root name, as it complains by saying:
"Context_Root_cannot_be_empty_2".

So I have to use a non-empty context root, such as "/MyWebProject". This
is very annoying because then the full URL will be:

http://myservername.com/MyWebProject

Of course, I can change the context root only at deployment time, but then
any internal links in my JSP code would also have to be changed, for
example, if on some page I want to link back to the website main page, I
have to put this in my JSP:

<a href="/MyWebProject">Back to the main page</a>

Which will work OK for testing but will stop working when I deploy it
under the "" context root in my production environment. After all, a
website address of the form http://myservername.com/MyWebProject is not
very nice.

Is this a bug or limitation of WTP? Has anyone also had this problem? I
think it could be easily corrected by just allowing the empty string as
the context root name, or maybe translating "/" into "" when publishing to
the Tomcat testing environment.

Thanks in advance,

Luis.
Re: Cannot set context root to "/" [message #169231 is a reply to message #169224] Fri, 12 May 2006 13:42 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: cooll.free.fr

Luis wrote:
> Is this a bug or limitation of WTP? Has anyone also had this problem?

I had the same problem with 1.0.0 and 0.7.1 (did not try 1.0.2 yet).

> <a href="/MyWebProject">Back to the main page</a>

You should use <a href="<%=request.getContextPath()%>/myURL" in your URLs to
make them independant against the deployment configuration
Re: Cannot set context root to "/" [message #169253 is a reply to message #169231] Fri, 12 May 2006 13:59 Go to previous messageGo to next message
Luis is currently offline LuisFriend
Messages: 20
Registered: July 2009
Junior Member
Lionel wrote:

> Luis wrote:
>> Is this a bug or limitation of WTP? Has anyone also had this problem?

> I had the same problem with 1.0.0 and 0.7.1 (did not try 1.0.2 yet).

>> <a href="/MyWebProject">Back to the main page</a>

> You should use <a href="<%=request.getContextPath()%>/myURL" in your URLs to
> make them independant against the deployment configurationT

Thank you... however, that is a workaround and the problem is still there
in WTP.

And this workaround has its limitations: for example it works with JSP
pages but not with HTML pages.

Regards,

Luis.
Re: Cannot set context root to "/" [message #169301 is a reply to message #169224] Fri, 12 May 2006 17:43 Go to previous messageGo to next message
Larry Isaacs is currently offline Larry IsaacsFriend
Messages: 1310
Registered: July 2009
Senior Member
There is a bug report for this already, see:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=137628

Another that impacts this problem is:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=125364

When the ".deployables" project subdirectory from WTP 0.7x went away and
webapp assembly duties moved to the server plug-ins, the Tomcat plug-in
began publishing to the "webapps" directory. That has the advantage of
being a simple approach. Unfortunately, the main disadvantage of that
approach is reflected in the two bugs above.

So far, I have been unsuccessful at finding a patch that is practical
for the 1.0.x or 1.5 time frame. It is straight forward enough to
achieve the desired behavior. The problem is doing so without breaking
other code that depends on the web application being deployed according
to it's deployment-name instead of the context-root. I don't anticipate
a problem straighting this out in WTP 2.0.

For now, I've found the following workaround, should you decide it is
worth the trouble to have a default webapp:

1. Leaving the context-root setting in the project as is (i.e. don't try
to set it to "/"), deploy the project to the Tomcat server.

2. Double-click on the Tomcat server in the Servers view to open the
configuration editor.

3. Switch to the Modules page of the editor and select the web module
for the project.

4. Click the "Edit..." button, clear the Path field, and click OK.

5. Save the Tomcat configuration and close the editor.

6. Right-click on the project in a navigator or a resource in the web
module and select Run As -> Run on Server.

7. Select the server to which the project was previously added and click
Next.

8. Click Next again. Uncheck the "Update context root for Web module..."
checkbox and click Finish. This will add a setting that prevents the
change made in step 4 from being overwritten by the project's
context-root setting. The browser should appear with the correct
default webapp appropriate URL.

If just starting and stopping the server, the desired behavior should be
maintained. However, if you make changes to the server by adding or
removing Web modules, then it is easy for this setting to get lost and
the project's context-root to get restored. You may have to repeat some
portion of the process. For example, if you remove a Web module,
repeating from step 6 will preserve the behavior. If you started the
server following the removal, then you will need to repeat from step 2.
If adding Web modules, using Run As -> Run on Server should give you
an opportunity to preserve the setting by not clicking Finish until you
get to the end of the wizard and performing step 8.

Also note that if auto deployment isn't turned off for the Tomcat
server, you will get a second copy of the Web module served with a path
equivalent to the project's name, i.e. bug 125364.

It should be noted that in step 4, specifying "/" as the path isn't
exactly the same as specifying "". The servlet spec requires "" for the
default webapp. It's likely that in many cases, "/" may be treated the
same as "", but this isn't guaranteed. It's a bug that an empty string
isn't accepted as the Context Root on the project properties J2EE page.

And one more final note, in Tomcat 5.5.17, directory listings are
disabled by default. If you don't have a welcome file available and
request "/", 404 is the expected response. Thus, it's possible to still
see a 404, even if you use the procedure above. Just add a welcome file
to correct. You will find this behavior to be true in some earlier
versions of 5.5.x as well, but I forget in which version the default
changed.

Cheers,
Larry


Luis wrote:
> Hello,
>
> I am using WTP 1.0.2.v200604280000, the "all in one" version that comes
> with Eclipse 3.1.2. I use Tomcat 5.5.17 as the server.
>
> I see I can change the context root of a web project by editing the
> project properties and then selecting the J2EE section, and it works
> perfectly well.
>
> But if I set the context root to "/", it simply does not work, and
> Tomcat returns a typical 404 error message: " The requested resource (/)
> is not available".
>
> Maybe this error has to do with the fact that Tomcat assumes that "" and
> not "/" is the way to identify a context root as the server root path,
> e.g.:
>
> <Host name="myservername.com" appBase="c:/Web">
> <Context path="" docBase="MyWebBase" />
> </Host>
>
> The problem then is that WTP does not allow me to provide an empty
> String as the context root name, as it complains by saying:
> "Context_Root_cannot_be_empty_2".
>
> So I have to use a non-empty context root, such as "/MyWebProject". This
> is very annoying because then the full URL will be:
>
> http://myservername.com/MyWebProject
>
> Of course, I can change the context root only at deployment time, but
> then any internal links in my JSP code would also have to be changed,
> for example, if on some page I want to link back to the website main
> page, I have to put this in my JSP:
>
> <a href="/MyWebProject">Back to the main page</a>
>
> Which will work OK for testing but will stop working when I deploy it
> under the "" context root in my production environment. After all, a
> website address of the form http://myservername.com/MyWebProject is not
> very nice.
>
> Is this a bug or limitation of WTP? Has anyone also had this problem? I
> think it could be easily corrected by just allowing the empty string as
> the context root name, or maybe translating "/" into "" when publishing
> to the Tomcat testing environment.
>
> Thanks in advance,
>
> Luis.
>
Re: Cannot set context root to "/" [message #169418 is a reply to message #169224] Mon, 15 May 2006 23:29 Go to previous message
Eclipse UserFriend
Originally posted by: nospam.thanks.com

Using Eclipse 3.2 RC4, WTP 1.5 and tomcat 5.5.17,

You can create a project with a "" contextroot,
but you can't change the context root of a project to ""
( "yourprojet">propertie>J2EE ),
Eclipse says "Context Root cannot be empty".


so,

define a project with blank contextroot during the creation

OR

edit the myworkspace\myproject\.settings\org.eclipse.wst.common.compo nent
file
like that:
<property name="context-root"/>
Previous Topic:images in a web project
Next Topic:how to use j2ee platform with eclipse
Goto Forum:
  


Current Time: Thu Nov 27 13:27:57 GMT 2014

Powered by FUDForum. Page generated in 0.02074 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software