How to Set Default URL of A Web-based Java Application Deployment in JSP

Posted on

This is an article where  the main goal is to show how to get default URL of a Web-based Java Application Development in JSP. Basically, the default URL which is discussed is the context root URL where it is used as the main URL to access the Web-based Java Application Development.

Based on several references popped-up in the Google search engine retrieved. It can be done basically depends on the Java Application Server used and in the context of this article, it is going to be performed in Wildfly Java Application Server. In order to add a context root URL as part of the Web-based Java Application accessed, just define it in the deployment descriptor of the Wildfly Java Application Server.

As the search process to find references in order to solve the problem, it seems the information or the definition which is given in the normal deployment descriptor located in WEB-INF/web.xml must have the appropriate tag to achieve it. But until this article is written, the first solution taken is actually to define in the specific deployment descriptor where in the context of this article, since the Java Application Server is Wildfly, the deployment descriptor’s file is jboss-web.xml.

So, in the directory of WEB-INF, there will be two deployment descriptor. The first one, a file named ‘web.xml’ which is a normal deployment descriptor. The other one, it is the specific deployment descriptor created for Wildfly Java Application Server named ‘jboss-web.xml’. The last file is the solution for defining the context root of the Java Web-based Application taken. Just define the following tag inside the file as follows :

<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->

<jboss-web>
<context-root>/webapp</context-root>
</jboss-web>

Try to define the

<context-root>/webapp</context-root>

inside the web.xml as shown below :

<?xml version=”1.0″ encoding=”UTF-8″?>
<!–
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
–>
<web-app xmlns=”http://xmlns.jcp.org/xml/ns/javaee”
xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”
xsi:schemaLocation=”http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd”
version=”3.1″>
<context-root>/webapp</context-root>

</web-app>

But it end up with an error specified as follows :

&&& SAX error: [27:11] null / null / org.xml.sax.SAXParseException; lineNumber: 27; columnNumber: 11; cvc-complex-type.2.3: Element 'web-app' cannot have character [children], because the type's content type is element-only.
&&& SAX error: [14:19] null / null / org.xml.sax.SAXParseException; lineNumber: 14; columnNumber: 19; cvc-complex-type.2.4.a: Invalid content was found starting with element 'context-root'. One of '{"http://xmlns.jcp.org/xml/ns/javaee":module-name, "http://xmlns.jcp.org/xml/ns/javaee":description, "http://xmlns.jcp.org/xml/ns/javaee":display-name, "http://xmlns.jcp.org/xml/ns/javaee":icon, "http://xmlns.jcp.org/xml/ns/javaee":distributable, "http://xmlns.jcp.org/xml/ns/javaee":context-param, "http://xmlns.jcp.org/xml/ns/javaee":filter, "http://xmlns.jcp.org/xml/ns/javaee":filter-mapping, "http://xmlns.jcp.org/xml/ns/javaee":listener, "http://xmlns.jcp.org/xml/ns/javaee":servlet, "http://xmlns.jcp.org/xml/ns/javaee":servlet-mapping, "http://xmlns.jcp.org/xml/ns/javaee":session-config, "http://xmlns.jcp.org/xml/ns/javaee":mime-mapping, "http://xmlns.jcp.org/xml/ns/javaee":welcome-file-list, "http://xmlns.jcp.org/xml/ns/javaee":error-page, "http://xmlns.jcp.org/xml/ns/javaee":jsp-config, "http://xmlns.jcp.org/xml/ns/javaee":security-constraint, "http://xmlns.jcp.org/xml/ns/javaee":login-config, "http://xmlns.jcp.org/xml/ns/javaee":security-role, "http://xmlns.jcp.org/xml/ns/javaee":env-entry, "http://xmlns.jcp.org/xml/ns/javaee":ejb-ref, "http://xmlns.jcp.org/xml/ns/javaee":ejb-local-ref, "http://xmlns.jcp.org/xml/ns/javaee":service-ref, "http://xmlns.jcp.org/xml/ns/javaee":resource-ref, "http://xmlns.jcp.org/xml/ns/javaee":resource-env-ref, "http://xmlns.jcp.org/xml/ns/javaee":message-destination-ref, "http://xmlns.jcp.org/xml/ns/javaee":persistence-context-ref, "http://xmlns.jcp.org/xml/ns/javaee":persistence-unit-ref, "http://xmlns.jcp.org/xml/ns/javaee":post-construct, "http://xmlns.jcp.org/xml/ns/javaee":pre-destroy, "http://xmlns.jcp.org/xml/ns/javaee":data-source, "http://xmlns.jcp.org/xml/ns/javaee":jms-connection-factory, "http://xmlns.jcp.org/xml/ns/javaee":jms-destination, "http://xmlns.jcp.org/xml/ns/javaee":mail-session, "http://xmlns.jcp.org/xml/ns/javaee":connection-factory, "http://xmlns.jcp.org/xml/ns/javaee":administered-object, "http://xmlns.jcp.org/xml/ns/javaee":message-destination, "http://xmlns.jcp.org/xml/ns/javaee":locale-encoding-mapping-list, "http://xmlns.jcp.org/xml/ns/javaee":deny-uncovered-http-methods, "http://xmlns.jcp.org/xml/ns/javaee":absolute-ordering}' is expected.
&&& SAX error: [27:11] null / null / org.xml.sax.SAXParseException; lineNumber: 27; columnNumber: 11; cvc-complex-type.2.3: Element 'web-app' cannot have character [children], because the type's content type is element-only.

The error shown that the cannot be inserted inside the tag <web-app></web-app>. Still trying to find out where is the exact location to put the tag <context-root>webapp</context-root> or maybe there is a different XML schema definition for the deployment descriptor to use the <context-root>webapp</context-root> tag.

So, the temporary solution is just to define it in the Wildfly Java Application Server’s deployment descriptor file. So, the application itself can be accessed through the URL context root pattern of : http://localhost:8080/webapp.   The last string, the ‘/webapp’ is the actual context root URL value defined in the deployment descriptor file.

One thought on “How to Set Default URL of A Web-based Java Application Deployment in JSP

Leave a Reply