Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2007

Tip: Looking for answers? Try searching our database.

how can I get the servlet access url from servlet context

Thread view: 
shaoanqing@gmail.com - 18 Apr 2007 09:10 GMT
hi
 I am coding for a WebApp
 I wrote a servlet and defined the mapping in web.xml like:

   <servlet>
       <display-name>MySer</display-name>
       <servlet-name>MySer</servlet-name>
       <servlet-class>com.santa.servlet.MyServlet</servlet-class>
       <load-on-startup>30</load-on-startup>
   </servlet>
  <servlet-mapping>
       <servlet-name>MyServlet</servlet-name>
       <url-pattern>/service/MySer</url-pattern>
   </servlet-mapping>

   I am now can access the servlet using the URL:
http://localhost:8080/myapp/service/MySer

 the question is how can I  get the URL from the servlet Context
 or at least how can I get the url pattern("service/MySer") from
servletContext?

thanks.
Arne Vajhøj - 19 Apr 2007 02:52 GMT
>     I am now can access the servlet using the URL:
> http://localhost:8080/myapp/service/MySer
>
>   the question is how can I  get the URL from the servlet Context
>   or at least how can I get the url pattern("service/MySer") from
> servletContext?

request.getRequestURL()

Arne
santax - 20 Apr 2007 02:06 GMT
> shaoanq...@gmail.com wrote:
> >     I am now can access the servlet using the URL:
[quoted text clipped - 7 lines]
>
> Arne
Thanks.
I am sorry , I was not present my problem clearly,
I want get the URL before any user accessing it.
I set the servle as load-on-startup servlet by definded below in
web.xml

<servlet>
       <display-name>MySer</display-name>
       <servlet-name>MySer</servlet-name>
       <servlet-class>com.santa.servlet.MyServlet</servlet-class>
       <load-on-startup>30</load-on-
startup>
<<---------------------------------------- init the servlet when
server start
   </servlet>
  <servlet-mapping>
       <servlet-name>MyServlet</servlet-name>
       <url-pattern>/service/MySer</url-pattern>
   </servlet-mapping>
so ,I want get the url-pattern in the method

@Override
    public void init(ServletConfig arg0) throws ServletException {
        System.out.println("*****************************");
               // I want get the url-pattern here
        System.out.println("*****************************");
        super.init(arg0);
    }

Thank you very much for your reply.
angrybaldguy@gmail.com - 20 Apr 2007 08:04 GMT
> > >     I am now can access the servlet using the URL:
> > >http://localhost:8080/myapp/service/MySer
[quoted text clipped - 11 lines]
> I want get the URL before any user accessing it.
> I set the servle as load-on-startup servlet by definded below in
web.xml

>  <servlet>
>         <display-name>MySer</display-name>
[quoted text clipped - 20 lines]
>
> Thank you very much for your reply.

Who says there is one?  There could be none at all, if load-on-startup
is turned on on the servlet entry.  For that matter there could be
several distinct mappings configured.

The only time URL information is available to a servlet is when it's
processing a request.  During that time the URL used for that request
is available to the servlet.  Your container (eg., Tomcat or Weblogic)
may provide extensions that allow you more detailed access to the
application configuration, but the Java EE specification doesn't
require it.
santax - 20 Apr 2007 10:10 GMT
> > > >     I am now can access the servlet using the URL:
> > > >http://localhost:8080/myapp/service/MySer
[quoted text clipped - 48 lines]
> application configuration, but the Java EE specification doesn't
> require it.

So  i can't get the url-pattern during init of servlet as your reply.
Then is there any way reading the web.xml directly??


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.