Meaningless Drivel is fun!*
The moose likes Servlets and the fly likes How to call a servlet from a browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How to call a servlet from a browser" Watch "How to call a servlet from a browser" New topic
Author

How to call a servlet from a browser

matteo depasquali
Greenhorn

Joined: Dec 14, 2012
Posts: 2
Hello everybody,
I hope all of you understand my poor english; after solving many problems by reading this forum, i've just signed up, and this is my first question

I'd like to know how to call a servlet by using a URL.
Now i'm able to call the servlet this way beacuse i set my web.xml this way

Is there a way to call my servlet by using its name, for instance http://localhost:8080/servlet/provaservlet/ServletName?

I set the <url-pattern> element with everythings come to me, but i didn't get my goal yet!
Pyla Rao
Ranch Hand

Joined: Jul 10, 2012
Posts: 50
Hi

Welcome to coderanch.

use following code may it solves



you can give url in url pattern then it matches respective servlet using web.xml. It is basic thing about servlets.


gurunath pai
Greenhorn

Joined: Dec 10, 2012
Posts: 13

Here ServletName is nothing but the URL-pattern, which you have defined in web.xml of application. Container internally calls the Servlet which is mapped to URL-pattern. You need go through some J2EE tutorial, best book would be Head first servlets and Jsp.

http://localhost:8080/servlet/provaservlet/ServletName

“Anyone who has never made a mistake has never tried anything new.” ― Albert Einstein
matteo depasquali
Greenhorn

Joined: Dec 14, 2012
Posts: 2
Thank you, now it works.
The correct url is http://localhost:8080/projectFolder/url-pattern and not http://localhost:8080/servlet/projectFolder/url-pattern

Reading guides and articles i often saw the folder called "servlet", and i thought it was necessary to tell tomcat that i was calling a servlet.

Actually, in the example i read on the internet, the folder called "servlet", was the name of the web project
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60760
    
  65

This is why it's important to use good names. "servlet" as the name of a web app is very poor and confusing, as you have discovered.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to call a servlet from a browser
 
Similar Threads
Wildcard servlet mappings in web.xml - how to get the part behind the * ?
Problem with DispatcherServlet mapping
The requested resource (/mycode/AA) is not available
Servlet Mapping
deploying an application