Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Context and Session  RSS feed

 
Sumesh Kumar T N
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anybody please give me the exact meaning of context (mainly context). I have a vague idea that a context is the directory in which we have created our project. Suppose its is /webapps/sumesh then I feel all the servlets written in /webapps/sumesh/WEB-INF/classes correspond to sumesh context. Is it correct. Please give me a good explanation about the topic because I feel listening to a person who knows the topic well is better than gorging on books.............
 
Ritu varada
Ranch Hand
Posts: 119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please give me a good explanation about the topic because I feel listening to a person who knows the topic well is better than gorging on books.............


Well, we all need to do that from time to time

Essentially, in the web development context, a "context" means application wide. Suppose, I need to add an attribute which all of your servlets use. Use a "context-level" (application-level) attribute. That is the essential meaning of context!
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may also be thinking of the concept of "context root" which in web applications refers to the part of the url that will call the particular J2EE application that I'm developing.

for example, if I call the URL

http://myserver.mycompany.com/myApplication

myserver.mycompany.com directs the user to a specific IP address where a webserver or J2EE application server resides. The /myApplication is the context root, and this tells the J2EE application server which application is being referred to.

When I create a WAR file, any jsp files that I place in the root of the WAR file, can be called by simply supplying the context root and the name of the jsp file as in:

http://myserver.mycompany.com/myApplication/myjsp.jsp

if I have created a servlet an placed an entry in web.xml for it such as:
<servlet>
<display-name>TestServlet</display-name>
<servlet-name>TestServlet</servlet-name>
<servlet-class>servlet.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/TestServlet</url-pattern>
</servlet-mapping>

In this case the servlet can be called by:

http://myserver.mycompany.com/myApplication/TestServlet

In most cases the servlet.TestServlet class file will be in /WEB-INF/classes, but it could be anywhere in the classpath the application server points to.

The concept of context in this case means that any classes in your war file in the /WEB-INF/classes directory or in jar files in the /WEB-INF/lib directory are avialable to servlets or jsps called with the /myApplication context root.

Where those files reside while you are developing them doesn't really matter. The application server you use will deploy them to wherever it needs them when you deploy the web application. Your job is to see that when you assemble the war file, that the files are in the right place.

I hope this helps.

Merrill
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!