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.
> > > 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??