How to invoke a Servlet?
Answers were Sorted based on User's Feedback
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 |
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 |
How can we invoke another servlet in a different application?
How can the referrer and the target urls be used in servlet?
What is filter? Can filter be used as request or response?
When jsessionid is created?
how can we create object to a class in a jsp file?
5 Answers Accenture, L&T, TCS,
What are the types of protocols supported by httpservlet ?
difference between sendredirect,forward and url rewritting
give the syntax of doGet() and doPost()?
Differentiate between the print writer and servlet output stream?
What do you mean by interservlet communication?
What do you mean by request dispatcher in servlet? Also explain its methods.
How to get ip address in jsp login page and how to validate like 127.1.0.1 all should not be greater than 255