• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

Problem of finding the Context URL in WebApplication

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am working with Web-Application (TestApp). In this application i used to implement the ServletContextListener(as ContextListener) and
contextInitialized(ServletContextEvent event) method contains the following code segment.

ServletContext servletContext = event.getServletContext();
// where event is ervletContextEventURL
String servletPath = servletContext.getContextPath()+"/MyServlet";
// MyServlet is URL of the Servlet
URL servletURL = sevletContext.getResource();

Here i am trying to get the complete URL of MyServlet ( expected servletURL = http://localhost:8080/TestApp/MyServlet) but it always returns '0'.
And servletContext.getContextPath() always returns /TestApp (expected http://localhost:8080/TestApp).

Anybody please suggest me that is there any way to find URL of context(http://localhost:8080/TestApp)
OR particular Servlet from ServletContext(http://localhost:8080/TestApp/MyServlet).

Using ApplicationServer : Jboss AS 7.1.1
 
Ranch Hand
Posts: 138
Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have you tried using getRealPath(String path) of ServletContext?
 
kishore routhu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes i tried with getRealPath("/MyServlet") but it returns as follows

/usr/java/jboss/jboss-as-7.1.1.Final/standalone/tmp/vfs/temp8e6f1bb35e6dff50/TestApp.war-bdc0e65482008d47/MyServlet
 
Sheriff
Posts: 67597
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You cannot get the URL of a servlet because that is controlled by the mappings in the web.xml, not their location in the file system.
 
kishore routhu
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I need to get the context URL
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic