【问题标题】:Hide form action value in the URL in JSP在 JSP 中的 URL 中隐藏表单操作值
【发布时间】:2013-04-20 04:29:15
【问题描述】:

我正在用 Java 创建一个 Web 应用程序。我创建了一些 JSP 页面,每个页面都有一些表单字段。所有都是 post 方法类型,因此它隐藏了所有表单字段。在每个页面中,它将调用 servlet 并转发到下一个 JSP 页面(就像一个逐步的过程。))欢迎页面是 index.jsp。在最后一个 JSP 页面中,我也有表单字段,它也是 post 方法类型。当我按下 sumbit 按钮时,它会调用 servlet 并应该转发到主页(即index.jsp)。

最后一页操作值为finish。在我的 servlet 中,我使用 RequestDispatcher 并转发到 index.jsp。该网址将是

http://localhost:8080/myproject/finish。 因为它是主页,所以我想隐藏该操作值。所以我用的不是RequestDispatcher response.sendRedirect("index.jsp"); 然后 URL 变成 http://localhost:8080/myproject/index.jsp.

这不是什么大问题。但我仍然在问是否有在 URL 中隐藏这个 index.jsp ?应该是第一次打开网站时的样子(http://localhost:8080/myproject/)。

【问题讨论】:

  • 试试response.sendRedirect("/");
  • 转到http://localhost:8080/
  • 谢谢。我试过response.sendRedirect("/myproject");

标签: java jsp servlets


【解决方案1】:

我终于得到了答案。感谢@Sayem Ahmed 作为 cmets 的回复。

我只试过这个

response.sendRedirect("/myproject");

【讨论】:

  • 使用你的上下文路径作为硬编码字符串是个坏主意!你应该使用response.sendRedirect(request.getContextPath())。您的上下文路径“/myproject”将来可能会改变!
猜你喜欢
  • 1970-01-01
  • 2019-01-01
  • 1970-01-01
  • 2013-12-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多