Java get url servlet

Java Servlet : Get URL Example

In this tutorial, You will learn how to get url of servlet.

In this tutorial, You will learn how to get url of servlet.

Java Servlet : Get URL Example

In this tutorial, You will learn how to get url of servlet.

Servlet getRequestURL :

getRequestURL() method reconstruct the requested client URL. It returns the current URL which containing protocol, server name, port number and server path. It doesn’t include query string parameters. It returns URL in StringBuffer in place of String so if required you can add query string parameters.

Example : In this example we are using getRequestURL() method to get current URL.

GetURLExample.java

package net.roseindia; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class GetURLExample extends HttpServlet < public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException < response.setContentType("text/html"); PrintWriter out = response.getWriter(); out.println("Current URL : " + request.getRequestURL()); >>
  ServletExample  GetURLExample net.roseindia.GetURLExample  GetURLExample /getURLExample  index.jsp   

Источник

Читайте также:  Как правильно установить java
Оцените статью