我在jsp页面上工作,我有一个带有2个参数的链接: shop.jsp:
<a href="<c:url value="/boutique?achat=${module.id}&token=${module.token}" />" class=" modal-action modal-close waves-effect waves-green btn-flat">Oui</a>
所以我在我的servlet中有两个参数来处理这两个参数: shop.java:
public void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException
{
httpServletRequest.setAttribute("page", "boutique");
HttpSession session = httpServletRequest.getSession(true);
int tokens = moduleDAO.getTokens(session.getAttribute("sessionPlayer"));
List<Module> modules = moduleDAO.select();
httpServletRequest.setAttribute("modules", modules);
httpServletRequest.setAttribute("tokens", tokens);
if(httpServletRequest.getParameter("achat") != null)
{
inventoryDAO.addInventory(session.getAttribute("sessionPlayer"), Integer.parseInt(httpServletRequest.getParameter("achat")));
}
if(httpServletRequest.getParameter("token") != null)
{
inventoryDAO.changeToken(session.getAttribute("sessionPlayer"), Integer.parseInt(httpServletRequest.getParameter("token")));
}
getServletContext().getRequestDispatcher("/WEB-INF/shop.jsp").forward(httpServletRequest, httpServletResponse);
}
但是我想点击带有2个参数的舔后刷新我的页面,因为在我的shop.jsp页面中我有一个值:$ {tokens},它没有刷新,因为当我点击链接时我仍然使用2个参数。
那么在点击链接后如何刷新页面?
谢谢!
我做了:
if(httpServletRequest.getParameter("token") != null)
{
inventoryDAO.changeToken(session.getAttribute("sessionPlayer"), Integer.parseInt(httpServletRequest.getParameter("token")));
String referer = httpServletResponse.getHeader("/WEB-INF/boutique.jsp");
httpServletResponse.sendRedirect(referer);
}
getServletContext().getRequestDispatcher("/WEB-INF/shop.jsp").forward(httpServletRequest, httpServletResponse);
但是我得到一个错误:在得到回应后不能使用前进
答案 0 :(得分:0)
我在stackoverflow上找到了另一个问题,我添加了一个返回;:
if(httpServletRequest.getParameter("token") != null) {
inventoryDAO.changeToken(session.getAttribute("sessionPlayer"), Integer.parseInt(httpServletRequest.getParameter("token")));
httpServletResponse.sendRedirect("/galactium/boutique");
return;
}