How to Specify the Root Context in Your <Web-App> Tags in Web.Xml

How to setting context root in web.xml in servlet ??

You have to delete ROOT webapp from Tomcat.

From Tomcat documentation : http://wiki.apache.org/tomcat/HowTo#How_do_I_override_the_default_home_page_loaded_by_Tomcat.3F

The pages and code of your "mywebapp" application currently reside in
(CATALINA_BASE)/webapps/mywebapp/. In a standard Tomcat installation,
you will notice that under the same directory
(CATALINA_BASE)/webapps/, there is a directory called ROOT (the
capitals are important, even under Windows). That is the residence of
the current Tomcat default application, the one that is called right
now when a user calls up "http://myhost.company.com[:port]". The trick
is to put your application in its place.

First stop Tomcat. Then before you replace the current default
application, it may be a good idea to make a copy of it somewhere
else. Then delete everything under the ROOT directory, and move
everything that was previously under the
(CATALINA_BASE)/webapps/mywebapp/ directory, toward this
(CATALINA_BASE)/webapps/ROOT directory. In other words, what was
previously .../mywebapp/WEB-INF should now be .../ROOT/WEB-INF (and
not .../ROOT/mywebapp/WEB-INF).

Just by doing this, you have already made you webapp into the Tomcat
default webapp.

Restart Tomcat and you're done. Call up "http://myhost.company.com/"
and enjoy.

How to set the context path of a web application in Tomcat 7.0

What you can do is the following;

Add a file called ROOT.xml in <catalina_home>/conf/Catalina/localhost/

This ROOT.xml will override the default settings for the root context of the tomcat installation for that engine and host (Catalina and localhost).

Enter the following to the ROOT.xml file;

<Context 
docBase="<yourApp>"
path=""
reloadable="true"
/>

Here, <yourApp> is the name of, well, your app.. :)

And there you go, your application is now the default application and will show up on http://localhost:8080

However, there is one side effect; your application will be loaded twice. Once for localhost:8080 and once for localhost:8080/yourApp. To fix this you can put your application OUTSIDE <catalina_home>/webapps and use a relative or absolute path in the ROOT.xml's docBase tag. Something like this;

<Context 
docBase="/opt/mywebapps/<yourApp>"
path=""
reloadable="true"
/>

And then it should be all OK!

Java configure context root of web application

Set the runtime name when deploying your web application. Suppose your WAR is called myapp-1.0.0-SNAPSHOT.war. Using a runtime name of foo.war, the context root will be /foo.

Using a runtime name of ROOT.war, the context root will be /.

The runtime name can be set when deploying via the Web Console or via the CLI.

Configure the context path of a web app

The only way so far to set the context-root of a WAR so that it is independent of the application server being used is : make it a part of an EAR and supply the context-root via application.xml:

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" version="6">
<display-name>EAR_NAME</display-name>
<module id="Module_***********">
<web>
<web-uri>YourWeb.war</web-uri>
<context-root>YourContextRoot</context-root>
</web>
</module>
</application>

Even as of JAVA EE 6, the WAR's context-root has to be a part of either jboss-web.xml , glassfish-web.xml or similar server specific web deployment descriptor. Here is an official example.

I could not find similar example for JAVA EE 7, but i really don't think this has changed. JEE7 was mostly about adding features around HTML5 and JSON.

How to set the context root in java ee 7 application

By default, context root is the same as package name.

If you use wildfly or jboss, you can add jboss-web.xml to webapp/WEB-INF/ to change context root, content like:

<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.jboss.com/xml/ns/javaee
http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
<context-root>yourownroot</context-root>
</jboss-web>

How to add application context in web.xml

You're missing spring-web.jar in your classpath.

Try to add this in your maven configuration:

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<type>jar</type>
<scope>compile</scope>
</dependency>


Related Topics



Leave a reply



Submit