on 10-11-2007 12:01 PM
can someone tell me if it is mandatory to declare all servlets in the deployment descriptor?
Thanks & Regards,
Lekshmi
Yes, because otherwise it can't be accessed
But why would you code a servelt without using it?
regards franz
reward points if useful
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Since a servlet is a server side program, so due to security purposes end user can't access it directly. But since it have to serve the client request the only way to do this is using Deployment Descriptor (DD).
However the process to write DD will be the same across all the servers ( Web server & Application server).
Inside the web.xml we have to add the following elements :
<web-app>
<servlet>
<servlet-name>EmpServlet</servlet-name>
</servlet-class>web.EmployeeServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>EmpServlet</servlet-name>
</url-pattern>/servlet.*</url-pattern>
</servlet-mapping>
</web-app>
Now you can called this servlet like :
http://host-name:port-no/context-path/servlet.do
The servlet instance will be created when the first request comes. If you want to create the servlet instance before to serve the client request then we have to add the below element into web.xml :
<load-on-startup>1</load-on-startup>
This element have to be placed between <servlet></servlet>.
Message was edited by:
Durga Prasad Yyellapu
Message was edited by:
Durga Prasad Yyellapu
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Your web.xml will be like
<servlet>
<servlet-name>MyServletServlet</servlet-name>
<servlet-class>com.somepackage.TheServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServletServlet</servlet-name>
<url-pattern>*.some_pattern</url-pattern>
</servlet-mapping>
you can call your servlet only through your deployment descriptor, then only it will be called as a servlet, otherwise it would be a simple java class, and the server can read your web.xml only when it is restarted.
..............................
<b>Package Structure</b>
more thing is
if you change your package structure you can only change in the web.xml,
if you directly call your servlet you will have to change the package structure in your code, then you need to compile it again and then deploy it.
................................
<b>Security</b>
Usually your url pattern and servlet name will be different and you can hide users from knowing exact servlet name
Regards
Abhijith YS
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.