Monday, February 18, 2013

Dissection of URL of HTTP Requests in Java Web Applications

Java web applications are request-driven. A client (i.e. a web browser) sends a HTTP request to a server (e.g. Tomcat) and gets a HTTP response back, and displays content of the response. Every HTTP request has a URL. This article is a brief explanation of the structure of such URLs.

Overview

A typical HTTP request URL is like: http://www.mycompany.com/my-web-appliction/my-servlet?param1=value1&param2=value2

It begins with "http" or "https" - the request protocol.

In above example, www.mycompany.com is the full host name of the server. The place can also been taken by the IP address of the server. If the protocol is http but the server port is not 80 (or the protocol is https but the server port is not 443), the port number has to be appended to the host name, like in www.mycompany.com:8080. Here 8080 is the server port.

In above example,  my-web-appliction is the context root of the web application. The way to specify the context root of a web application depends on the application server (e.g. WebLogic server). More details on this will come later.

In above example, my-servlet is the servlet URL. A servlet's URL is specified in the web.xml file for the web application (every servlet is declared in a web application). Details will come later.

In above example, param1=value1&param2=value2 are the request parameters. They are name/value pairs. Withing a pair, the name and value are separated by =, and pairs are separated by & (or ;). In this example, there are two request parameters, named param1 and param2, and their value are respectively value1 and value2. In a generic HTTP URL, this part is called a query string, and is separated from the main URL by a character ?.

Specifying Context Root of a Web Application  in Apache Tomcat

In Tomcat, the name of the base direction of a web application is the context root. For example, if the base directory of a web application is tomcat/webapps/mywebapp, where tomcat is the installation directory of Tomcat, the context root is mywebapp.


Specifying Context Root of a Web Application in JBoss Server

It is the value of the <module>/<web>/<context-root> element in application.xml.

Specifying Context Root of a Web Application in WebLogic Server

It is the value of the <context-root> element in weblogic.xml for the web applicaiton (i.e. in the same directory as web.xml for the web application)

Specifying Context Root of a Web Application in WebSphere Server

It is the value of the uri attribute of the <context-root> element in the ibm-web-ext.xml for the web application (i.e. in the same directory as web.xml for the web application)


Specifying  Servlet URL

An example (partial) web.xml for a web application:

<servlet>
    <servlet-name>the-servlet-name</servlet-name>
    <servlet-class>com.mycompany.XyzServlet</servlet>
</servlet>

<servlet-mapping>
    <servlet-name>the-servlet-name</servlet-name>
    <url-pattern>/my-servlet</url-pattern> 
</servlet-mapping>


3 comments:

Megan Valish said...

Copa America 2016 Semifinal
copa america 2016 live streaming
copa America 2016 Final
copa America 2016 Live Online
Usa vs Argentina Copa America 2016 Semifinal
Colombia vs Chile Copa America 2016
Usa vs Argentina Live Streaming
Colombia vs Chile Live Streaming
Copa america Final
Watch Copa America Live Online
Copa America 2016 Semifinal
copa america 2016 live streaming
copa America 2016 Final
copa America 2016 Live Online
Usa vs Argentina Copa America 2016 Semifinal
Colombia vs Chile Copa America 2016
Usa vs Argentina Live Streaming
Colombia vs Chile Live Streaming
Copa america Final
Watch Copa America Live Online
Halloween 2016 Costumes Ideas
Happy Diwali 2016 Images
Get Passport Status
Passport Status
When Halloween 2016
Black Friday 2016 Deals
Ganesh Chaturthi 2016 Images
Independence Day 2016
Happy independence day 2016
Latest Government Jobs
Latest Bank Jobs
Champions Trophy 2017 Schedule
2017 Champions Trophy
Best Whatsapp Images
Narendra modi Speech
Top 10 Richest Cities In India

Raushni Singh said...

what is independence day
usa independence day 2016 Wishes
america independence day 2016 Quotes
Happy independence day 2016 images
happy 4th of july 2016 images
happy 4th of july 2016 pictures
independence day 2016 pictures
independence day 2016 pics
the independence day
4th july 2016 pictures
Happy 4th of july 2016 fireworks
4th july 2016 celebrations
Happy independence day 2016 Wishes
fourth of july 2016 quotes
independent quotes
4th of july 2016 wallpapers
4th of july 2016 photos
Happy 4th of july 2016 quotes
4th of july 2016 nail designs
4th of july 2016 nail Arts
Canada Day 2016 Graphics
happy birthday america
Canada Day 2016 Greetings
independence day 2016 sale
Happy Canada Day 2016
independence day history
july 4th 2016 sale
4th of july 2016 sales
Canada Day 2016 Quotes
4th of july 2016
4th of july 2016 events
july 4th 2016 fireworks

rajat kukkar said...

ipl 2017 schedule
IPL 2017 Fixture
ipl 2017
ipl 2017 teams
vivo ipl 2017 schedule
vivo ipl 2017 fixture
vivo ipl 2017
vivo ipl 2017 team
vivo ipl 2017 squard
IPL 10
IPL 10 Schedule
IPL 10 Teams
vivo IPL 10
vivo IPL 10 Schedule
vivo IPL 10 Teams