当前位置: 动力学知识库 > 问答 > 编程问答 >

How to serve existing web page using a java servlet

问题描述:

I've been through a few tutorials for java servlets and they all show how to display a web page generating in the java code using a servlet. How can I display an existing html page using a servlet?

I figure I need to do something with HttpServletRequest.getRequestDispatcher but not sure exactly what?

网友答案:

you can do this in two ways:

1) Request dispatcher

ServletContext context= getServletContext();
RequestDispatcher rd= context.getRequestDispatcher("/somePage.html");
rd.forward(request, response);

2) Request sendRedirect()

request.sendRedirect("/someUrl.html");

See the difference between the two methods here: requestDispatcher Interface Vs sendRedirect

分享给朋友:
您可能感兴趣的文章:
随机阅读: