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
Check if parameter exists in servlet request
will see how to check is parameter exists in servlet request. In this example... Check if parameter exists in servlet request... that is used to send a request to a servlet that execute the request and tests
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
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
url masking - JSP-Servlet
url masking  hi.........i am using tomcat in my local machine i have a project in tomcat named myproject for example to request that i use http://localhost:8080/myproject can i use abc.localhost in place of localhost
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
@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
Request for codes - JSP-Servlet
Request for codes  Sir , I am an engineering student i am interested in learning JAVA also i need some example code for creating Registration form codes for creating web based application using JSP sir plz send me which
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
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
request object - JSP-Servlet
request object  What is Difference Between request.getHeader("x-forwarded-for") and request.getServerName() pls give me reply as soon as possible
problem getting servlet:xmlHTTP.status=404 - Ajax
problem getting servlet:xmlHTTP.status=404   hi, ihave a text field in which i type some words and get related response from db via XMLHTTP request object.The problem is my script is unable to get the servlet in which i have
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
Servlet Example To Update Mysql Clob Data
example, servlet InsertClobExample takes url for the CLOB data (the url... Servlet Example To Update Mysql Clob Data  ... representing the CLOB; the servlet will open the url, construct a CLOB
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 an exception - JSP-Servlet
Getting an exception  thanks sir for u r reply ,but i already added that jar file sir even though i m getting an exception sir please help me sir ... thanks in advance..  Hi Friend, You can do one thing, replace
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
Servlet Example To Insert Mysql Clob Data
example, servlet InsertClobExample takes url for the CLOB data (the url... Servlet Example To Insert Mysql Clob Data  ...) sourceURL (the url of file representing the CLOB; the servlet will open
Getting an exception - JSP-Servlet
Getting an exception  sir i used u r code for sending a mass email by reading an excel sheet,but i am getting a following error so please help me if any changes in code . thanks in advance.. java.io.IOException: Invalid
Getting an exception - JSP-Servlet
Getting an exception  sir i used u r code for sending a mass email by reading an excel sheet,but i am getting a following error so please help me if any changes in code . thanks in advance.. java.io.IOException: Invalid
Not getting the logic - JSP-Servlet
Not getting the logic  there is one sub module in my project.In that it display the list of candidates in a grid table who are selected for the interview with inline edit and the field of the table contains one checkbox, e.g if 5
Getting an exception - JSP-Servlet
Getting an exception   sir i am Getting following exception when executing javax.servlet.ServletException: java.lang.NoClassDefFoundError: org/apache/poi/poifs/filesystem/POIFSFileSystem I have used ur code import
Getting an exception - JSP-Servlet
Getting an exception  Dear sir,while executing this code i am getting a following error ,i am sending my code also please help me sir... //following is a code int a = 0, b = 1, c = 2, d = 3, e = 4,f=0; //int a, b, c, d, e
Getting an exception - JSP-Servlet
Getting an exception  sir i m Getting an following exception while sending a mail with attachment value ofsession is [email protected]4 value of mimemessage is [email protected] value
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 an exception - JSP-Servlet
Getting an exception  sir i changed to that ie InputStream myInput1 = new FileInputStream(fileName); HSSFWorkbook myWorkBook = new HSSFWorkbook(myInput1); but when i click on a browse button and attached a file
request header and response - JSP-Servlet
request header and response  hi sir, i have facing some problem in this qustion:- Create a servlet that accept a name and a phone number and contain 4 buttons add,update,delete and view .On clicking on the any of the button
ServletFileUpload request getInputStream - JSP-Servlet
ServletFileUpload request getInputStream  Hi All, I want multiple... location(may be c:\.. or d:\..) from client browser to servlet file. Here is my servlet code. My problem is i don't know how to write multiple file
request header and response - JSP-Servlet
request header and response  Create aservlet that redirects a client to a.html if its morning ,to b.html if its a afternoon else to c.html.

Ads