How to invoke a Servlet?

Answers were Sorted based on User's Feedback



How to invoke a Servlet?..

Answer / chandra kunchala

you can invoke the servlet by two ways
one is dierctly u can invoke from address bar
like the following
http://<servername>:<port-Number>/<web-application-name>/<url-pattern
of perticular servlet>

eg:- http://localhost:8080/app1/test

second one is u can invoke by using form..
<form action="/app1/test">
.....
.....
</form>

web.xml:-

<servlet>
<servlet-name>FirstServlet</servlet-name>
<servlet-class>pack1.pack2.ClassName</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FirstServlet</servlet-name>
<url-pattern>/test</url-pattern>(test should be equal
to what u typed in the address bar after the web-application
name or should be equal to what u mention in the form action
after the web-application name)
</servlet-mappin>

Is This Answer Correct ?    16 Yes 7 No

How to invoke a Servlet?..

Answer / dara

<form action="/servlet/full.class.name">
</form>


This method uses the invoker servlet, provided by many
servlet containers. The much better way of invoking a
servlet is by providing an explicit mapping for it. This is
accomplished by using a pair of tags in your web
application's web.xml file. This is not the same file as
mentioned above. That file was located in Tomcat's conf/
directory. This web.xml file (which you will probably need
to create) will reside in your web-application's WEB-INF/
directory. For each servlet you want to call, provide a
pair of tags like the following:


...
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>your.package.name.HelloWorld</servlet-
class>
</servlet>
...
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/hello</url-pattern>
</servlet-mapping>
...

Is This Answer Correct ?    8 Yes 2 No

Post New Answer

More Servlets Interview Questions

What are the different methods of session management in servlets?

0 Answers  


What is Generic Servlet and how it is different from Http Servlet?

5 Answers   Wipro,


What are the exceptions thrown by servlets? Why?

0 Answers  


Write a program to show the functionality of doget and dopost method?

0 Answers  


Which is the methods of generated servlet?

0 Answers  






What is difference between cookies and httpsession?

0 Answers  


Explain the custom jsp tags and the beans.

0 Answers  


Why is a constructor needed in a servlet even if we use the init method?

0 Answers  


Why setMaxAge() and getMaxAge() methods are used in Cookies?

2 Answers  


request parameter how to find whether a parameter exists in the request object?

0 Answers  


What is a parser. What does a parser do with a XML? Why do we need it?

1 Answers  


What's the architecture of a servlet package?

0 Answers  


Categories