0

I have a Servlet/JSP application. I'm trying to display a customised URL for each Servlet:

Example, i have a servlet "First_step" that does some work, the URL diplayed is

http://localhost:8080/App/Fisrt_step 

How can i change it to display http://localhost:8080/App/home

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
K.br
  • 33
  • 4

1 Answers1

1

Depends on your web configuration. Are you on servlets 2.5 or 3.1 ? If you are still using 2.5, then you can change your servlet url mapping in your web.xml file located inside WEB-INF:

Your current mapping would look something like this *assuing your servlet class name is also "FisrtStepServlet" (FisrtStepServlet.class):

  <servlet>
    <display-name>FisrtStepServlet</display-name>
    <servlet-name>FisrtStepServlet</servlet-name>
    <servlet-class>yourpackage.FisrtStepServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>FisrtStepServlet</servlet-name>
    <url-pattern>/Fisrt_step </url-pattern>
    <url-pattern>/alternativeURL</url-pattern>
  </servlet-mapping>

if you are using 3.1, you can change the url mapping of your servlet with annotations.

@WebServlet("/Fisrt_step ") //here you change the servlet URL
public class FisrtStepServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    public FisrtStepServlet() {
        super();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    //whatever here

    }
}
Jonathan Laliberte
  • 2,672
  • 4
  • 19
  • 44