0
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.getWriter().append("Served at: ").append(request.getRequestURL());
    System.out.println("Received Value: "+request.getRequestURL());
    Utils.getDataFromFeedbackLink(request.getContextPath());        
    response.setContentType("text/html"); 
    PrintWriter pw=response.getWriter();      
    pw.println("<html><body>");  
    pw.println("Welcome to servlet"+request.getRequestURL());  
    pw.println("</body></html>");   
    pw.close();  

}

web.xml

 <servlet>
    <servlet-name>SubmitFeedbackServlet</servlet-name>
    <display-name>SubmitFeedbackServlet</display-name>
    <description></description>
    <servlet-class>com.techjini.tfs.servlets.SubmitFeedbackServlet</servlet-class>
  </servlet>
      <servlet-mapping>
        <servlet-name>SubmitFeedbackServlet</servlet-name>
        <url-pattern>/submitfeedback</url-pattern>
      </servlet-mapping>

this is my Code of servlet get method : i want to print what ever request URL will be Like http://localhost:8080/TechJiniFeedbackSystem/submitfeedback/Hello servlet

then this URL should Print in my Consle i have used getContextPath and getRequestURL but non of these printing http://localhost:8080/TechJiniFeedbackSystem/submitfeedback/Hello servlet

please suggest me where am doing wrong or suggest me to solve this issue .

1 Answer 1

1

It's incredible easy: you must use getRequestURL from HttpServletRequest in your Servlet in doGet method

or for more info you can use this methods: getServletPath(), getContextPath and etc.

read more in specification: https://docs.oracle.com/cd/E17802_01/products/products/servlet/2.5/docs/servlet-2_5-mr2/javax/servlet/http/HttpServletRequestWrapper.html#getRequestURL()

Sign up to request clarification or add additional context in comments.

2 Comments

nothing Print even page not loading localhost:8080/TechJiniFeedbackSystem/submitfeedback/hello wgen i use given URL
see this, PrintWriter is Evil, but for showcase example is enough, or use println in console mysamplecode.com/2011/05/java-servlet-get-request-url.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.