-2

リクエストディスパッチの場合、URLを変更することは可能ですか。

これは私のコードです

public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException
{

 List<HomePageServicesDescription> data= HomePageServicesDescriptionDB.showHomePageServicesDescription();
 req.setAttribute("description", data);

 req.getRequestDispatcher("index.jsp").forward(req,res);

 }

したがって、Webブラウザで表示するとhttp://localhost:8888/url-mapping、サーブレットのurl=が得られます。しかし、私はそのurl=が欲しいですhttp://localhost:8888/index.jsp。どのようにそれが可能であるか。

4

2 に答える 2

0

私は答えを得ました

public void doGet(HttpServletRequest req, HttpServletResponse res) 
    throws IOException, ServletException
{

    List<HomePageServicesDescription> data = HomePageServicesDescriptionDB.showHomePageServicesDescription();
    req.getSession().setAttribute("description", data);

    res.sendRedirect("index.jsp");

}

そしてindex.jspで

List<HomePageServicesDescription> data= (List<HomePageServicesDescription>) session.getAttribute("description");

その完璧な仕事

于 2012-07-12T05:54:18.333 に答える
0

HttpServletResponse.sendRedirect()の代わりに行う必要がありRequestDisaptcher.forward()ます。送信するパラメータはすべて、クエリパラメータとして送信できます。

public void doGet(HttpServletRequest req, HttpServletResponse res) 
        throws IOException, ServletException
{

   List<HomePageServicesDescription> data =
             HomePageServicesDescriptionDB.showHomePageServicesDescription();
    req.setAttribute("description", data);

    res.sendRedirect("index.jsp?description="+data);

 }
于 2012-07-11T12:38:25.677 に答える