invoking a servlet from an url

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • corejavaboy
    New Member
    • Oct 2007
    • 4

    invoking a servlet from an url

    Hi

    I have a servlet which I need to invoke from a jsp , thru an url
    I need to give a url which invokes my servlet , I have servlet and jsp in same application. can you help me how should I write url.

    Thanks
  • hirak1984
    Contributor
    • Jan 2007
    • 316

    #2
    Originally posted by corejavaboy
    Hi

    I have a servlet which I need to invoke from a jsp , thru an url
    I need to give a url which invokes my servlet , I have servlet and jsp in same application. can you help me how should I write url.

    Thanks
    first learn what is "servlet mapping" with respect to Web.xml.
    u have to give the mapping name in the url.

    Comment

    • corejavaboy
      New Member
      • Oct 2007
      • 4

      #3
      Originally posted by hirak1984
      first learn what is "servlet mapping" with respect to Web.xml.
      u have to give the mapping name in the url.
      I have learnt servlet mapping in the web.xml.
      Also , I have set url pattern.
      My question is , how should I write the url pattern,

      /servlets/myservlet

      or

      http://host/port/servlets/myservlet

      If second option is the correct one , what should I mention as host and port

      Thanks

      Comment

      • hirak1984
        Contributor
        • Jan 2007
        • 316

        #4
        Try this. It should help you.

        Code:
        	<servlet>
        		<description>
        		MyServlet</description>
        		<display-name>
        		MyServlet</display-name>
        		<servlet-name>MyServlet</servlet-name>
        		<servlet-class>
        		packagename.MyServlet</servlet-class>
        	</servlet>
        	
        	<servlet-mapping>
        		<servlet-name>MyServlet</servlet-name>
        		<url-pattern>/MyServlet</url-pattern>
        	</servlet-mapping>

        Comment

        Working...