Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsp 可以在请求调度程序中更改url_Jsp_Servlets_Requestdispatcher - Fatal编程技术网

Jsp 可以在请求调度程序中更改url

Jsp 可以在请求调度程序中更改url,jsp,servlets,requestdispatcher,Jsp,Servlets,Requestdispatcher,在发送请求时是否可以更改url 这是我的密码 public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException { List<HomePageServicesDescription> data= HomePageServicesDescriptionDB.showHomePageServicesDescription(); req.set

在发送请求时是否可以更改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);

 }
public void doGet(HttpServletRequest-req,HttpServletResponse-res)抛出IOException,ServletException
{
列表数据=HomePageServicesDescriptionDB.showHomePageServicesDescription();
请求设置属性(“说明”,数据);
req.getRequestDispatcher(“index.jsp”).forward(req,res);
}
因此,当在web浏览器中看到它时,它会给出url=
http://localhost:8888/url-servlet的映射

但是我想要那个url=
http://localhost:8888/index.jsp
。这怎么可能

您应该执行
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);

 }
public void doGet(HttpServletRequest-req,HttpServletResponse-res)
抛出IOException、ServletException
{
列表数据=
HomePageServicesDescriptionDB.showHomePageServicesDescription();
请求设置属性(“说明”,数据);
res.sendRedirect(“index.jsp?description=“+data”);
}
我得到了答案

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

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

    res.sendRedirect("index.jsp");

}
public void doGet(HttpServletRequest-req,HttpServletResponse-res)
抛出IOException、ServletException
{
列表数据=HomePageServicesDescriptionDB.showHomePageServicesDescription();
req.getSession().setAttribute(“说明”,数据);
res.sendRedirect(“index.jsp”);
}
在index.jsp中

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

非常好

再次感谢,先生,但我想设置请求属性。先生,有任何方法可以帮助我。发送查询参数并作为重定向servlet上的ServletRequest.getParameter(“description”)访问它。问题是什么?先生,它在jsp页面列表=(列表)ServletRequest.getParameter(“描述”)中不起作用;它给出了错误我已经发布了servlet&jsp代码

ServletRequest是class,您应该给出对象变量,它是request。所以它应该是request.getParameter(“description”)