aspose file tools*
The moose likes Servlets and the fly likes URL and mapping to servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "URL and mapping to servlets" Watch "URL and mapping to servlets" New topic
Author

URL and mapping to servlets

Yile Ku
Greenhorn

Joined: Jan 27, 2011
Posts: 13
So all of the servlet examples show http://www.somehost.com:8080/ServletName. That works ok. but from outside users are going to type http://www.somehost.com/SomePage.html. I know that SomePage.html can invoke ServletName, but can an outside user invoke a serverlet directly by typing some non-8080 URL like http://www.somehost.com/Start where Start invokes my servlet?
Rajani Gummadi
Ranch Hand

Joined: Dec 17, 2010
Posts: 48
Yile Ku wrote:So all of the servlet examples show http://www.somehost.com:8080/ServletName. That works ok. but from outside users are going to type http://www.somehost.com/SomePage.html. I know that SomePage.html can invoke ServletName, but can an outside user invoke a serverlet directly by typing some non-8080 URL like http://www.somehost.com/Start where Start invokes my servlet?


Hi Yile, as far as I know, HTTP servlets are based on HTTP/HTTPS request/response semantics.. I have not seen examples where servlets can be invoked in non HTTP/HTTPS mode.

If you are asking if a servlet can be invoked in otherways instead of pointing to URL, Certainly yes. You can open a HTTPConnection to the servlet, but again 8080 is the protocol that is used underneath.

As you are aware HTTPServlet extends GenericServlet which is basically meant for protocol independent purpose. But I have not encountered any examples in real time. I hardly believe if they actually exist anymore.
Yile Ku
Greenhorn

Joined: Jan 27, 2011
Posts: 13
Thanks for the reply. I want to access the application by a normal HTTP request without the :8080 socket descriptor. So the steps as I see them is that a user types in a URL (http://www.someserver.com/servletapp) and the apache or iis server gets the request. The webserver figures out somehow that servletapp is a servlet and not a web page, passes the request to tomcat which in turn runs the servlet. So the question is how does the webserver figure out that 'servletapp' (the URL does not have the :8080 socket descriptor) is a servlet and not a regular html page?
M-
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

To avoid the 8080, configure your server to listen on the default port of 80.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Yile Ku
Greenhorn

Joined: Jan 27, 2011
Posts: 13
Apache or IIS are listening in port 80.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18650
    
    8

But you want your servlet's application container to listen on port 80 instead? Then turn off those applications which are already using that port.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
So the question is how does the webserver figure out that 'servletapp' (the URL does not have the :8080 socket descriptor) is a servlet and not a regular html page?


A Java-based web server is aware of the Java servlets it has deployed in its Servlet Container. It is designed to call the servlet in the same way it serves up an HTML file from the filesystem.

Whether there is or is not a port number in the path has nothing to do with executing servlets or serving static HTML files.


You can certainly access a Java web application with http://www.domain.com/servletapp. If you are getting errors then you have not deployed the servlet correctly.

I know that SomePage.html can invoke ServletName, but can an outside user invoke a serverlet directly by typing some non-8080 URL like http://www.somehost.com/Start where Start invokes my servlet?


What happens when you try it?

Yile Ku
Greenhorn

Joined: Jan 27, 2011
Posts: 13
I get a 404 error. so how does one verify that the servlet and container are setup for a certain non-8080 URL?
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
First, port numbers are not included in domain names. Whatever web page examples you have read which show this are incorrect.

If you have not set up or registered a domain name mapping via DNS to a web server, then you still have a ways to go before making a servlet call using a domain name.

If you are getting a 404 error while trying to execute a servlet using a local URI, then you either have not deployed the servlet properly or the URI is incorrect.

I suggest a good reading of a Java Servlet book. Asdide, you can map a web server to any one of thousands of numbers. There is nothing special about 8080 or 80, except for the fact that they are used as a common "default" setting. This is easily changed, and changing it is a standard good practice in commercial settings.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: URL and mapping to servlets