Example of Getting request URL in a servlet

Ads
 

Example of Getting request URL in a servlet

One servlet can be configured to handle a set of requests. So, in Servlet you have to get the URL of the page accessed.

How you can get the URL of the page accessed in the Servlet?

Thanks

View Answers

June 4, 2015 at 11:33 AM

Hi,

The interface javax.servlet.http.HttpServletRequest provides a method

getRequestURL()

Which reconstruct the original url that client used to access the current resource (in this case Servlet) on the Server.

So, to ge the URL of the page used by the client to access the Servlet following code can be used:

System.out.println("Current URL : " + request.getRequestURL());

Check the tutorial Java Servlet : Get URL Example for complete web application code.

Thanks

Ads









Related Tutorials/Questions & Answers:
Example of Getting request URL in a servlet
Example of Getting request URL in a servlet  One servlet can be configured to handle a set of requests. So, in Servlet you have to get the URL...()); Check the tutorial Java Servlet : Get URL Example for complete web application
How to Get Referer URL Servlet
How to Get Referer URL Servlet In this section we will discuss about getting the referer url in Java. This example explains you how to get the referer url in Servlet. This tutorial explains you all the steps of getting the referer url
Advertisements
Java Servlet : Get URL Example
Java Servlet : Get URL Example In this tutorial, You will learn how to get url of servlet. Servlet getRequestURL : getRequestURL() method reconstruct...-name> <url-pattern>/getURLExample</url-pattern> </servlet
How send different files to browser at same time ..example(pdf&html) want display in same request using servlet
at same time ..example(pdf&html) want display in same request using servlet...How send different files to browser at same time ..example(pdf&html) want display in same request using servlet  package com.readfiles; import
Getting an exception - JSP-Servlet
Getting an exception  Dear Sir , While sending a mail am getting an following exception javax.mail.MessagingException: 554 mail server permanently rejected message (#5. 3.0)so how to over come from this please help
Getting data from servlet into javascript
Getting data from servlet into javascript  How do i get json data from my servlet on to a variable in javascript n bind the data to display onto sigma grid.Has anyone Idea how to do
how to get request url in node js
how to get request url in node js  Hi, I want to get the request url in Node js. how to get request url in node js? Thanks   Hi, Node... of request. how to get request url in node js? Here is the code: console.log
how to get request url in node js
how to get request url in node js  Hi, I want to get the request url in Node js. how to get request url in node js? Thanks   Hi, Node... of request. how to get request url in node js? Here is the code: console.log
@WebServlet Url Embedding Example
Servlet Url Embedding Example In this tutorial you will learn how can you embed the url of another web component in servlet. Embedding URL is a process... by the request URL subsequent to the path. Example UrlRequestExample.java package
Java Servlet : Http Request Headers
Java Servlet : Http Request Headers In this tutorial, you will learn how to Http Request Headers works in java servlet. Http Request Headers : HTTP... in orignal URL User-Agent  : type of browser, useful if servlet
JMeter HTTP request example
JMeter HTTP request example  Concerning: http://www.roseindia.net/jmeter/using-jmeter.shtml how do I set path? also what do i need to do to get the helloworld servlet work? Thanks in advance
ModuleNotFoundError: No module named 'url-request-scheduler'
ModuleNotFoundError: No module named 'url-request-scheduler'  Hi...: No module named 'url-request-scheduler' How to remove the ModuleNotFoundError: No module named 'url-request-scheduler' error? Thanks   Hi
how to retrieve the url pattern of the requesting servlet?
how to retrieve the url pattern of the requesting servlet?  Hi friends, I need to know this. For example if you have Servlet1 and Servlet2. Now from... the url pattern of the servlet1? This is my question. please answer me soon
Getting Json data from servlet to javascript variable
Getting Json data from servlet to javascript variable  How do i get json data from my servlet on to a variable in javascript n bind the data to display onto sigma grid.Has anyone Idea how to do
long url to short url for jsp or servlet
long url to short url for jsp or servlet  I have to convert a url "http://localhost:8080/Popup/popup?phone=111111111". I am unable to do the same. Please any help
Example questions of JSP & Servlet
Example questions of JSP & Servlet  Give me some JSP & Servlet Question and their answers
Java Servlet : Hello World Example
Java Servlet : Hello World Example In this tutorial, we are discussing about Servlet with simple Hello World Example. Java Servlet : A servlet is web...; for writing simple hello world example of servlet. Step1 : Write servlet, a POJO
Request URl using Retrive data from dtabase
Request URl using Retrive data from dtabase  Using With GWT the user... the contents from the db based on the event id. But this jsp url should be a public url. Means anyone can access it directly. ( something like
Servlet hello world example
interface. Servlet are responsible to handle web request. The javax.servlet.... After initialization of Servlet , Servlet instance can service client request... the service() method of the Servlet for every request. Service method will find
Java Servlet : URL Rewriting
Java Servlet : URL Rewriting In this tutorial, we will discuss about URL... session ID. Example : In this example we are using URL rewriting concept...-mapping> <servlet-name>UrlRewritingExample</servlet-name> <url
getting dropdown values using apache commons in servlet
getting dropdown values using apache commons in servlet  i want... public void doPost(HttpServletRequest request, HttpServletResponse response.../Desktop/output/"; isMultipart = ServletFileUpload.isMultipartContent(request
How to send URL in Post request from local server to remote server?
How to send URL in Post request from local server to remote server?  I am having currently a Portal client(created using JSP and Servlet) and Portal... to another server remotely?What to do in code??? 2> How to send a Post Request
@WebListener Annotation Servlet Example
@WebListener Annotation Servlet Example In this tutorial you will learn what... and servlet 3.0 (Java EE6). The example given below will demonstrate you how to implement a listener interface in servlet. In this example I will use
Getting Parameter from a css styled jsp file to a java servlet file...
Getting Parameter from a css styled jsp file to a java servlet file... ...;/code> methods. * @param request servlet request * @param response...;GET</code> method. * @param request servlet request * @param
Servlet: What is it
. It interacts with clients via request-response programming model. Servlet... servlet. Servlet invokes a single thread for each user request rather than... Servlet do? A servlet is a class, which responds to HTTP request. It receives a HTTP
Java Servlet : Get URI Example
Java Servlet : Get URI Example In this section, we will discuss about... string in the first line of the HTTP request. Example :  In this example...-mapping> <servlet-name>GetURIExample</servlet-name> <url
Which request executed first Out of multiple requests in servlet
Which request executed first Out of multiple requests in servlet  Servlet handles multiple request simultaneously.Every new request will be assigned... to servlet ,which request will be executed first , please correct me if question
Session Tracking Servlet Example
Session Tracking Servlet Example In this tutorial you will learn how to track... the maximum inactive interval, attribute and making request for the URL & URI... { doGet(request,response); } } Output : When you will execute the above example
Getting Image from a URL
Getting Image from a URL       This example shows how to get an image from the given URL. Description of program:  In the example given below, we
Java Servlet : Reading Form Data Example
Java Servlet : Reading Form Data Example In this tutorial, we are discussing about reading form data of a servlet. Reading Form Data : There are three...;/servlet-name> <url-pattern>/getParameterExample</url-pattern> <
jsp request in struts1
jsp request in struts1  how the request for a JSp is processed in Struts1?Any JsP page in the end a servlet only.where is the URL pattern for this servlet

Ads