Jsp 可以在请求调度程序中更改url
在发送请求时是否可以更改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
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”)