java - Spring MVC Controller 更改 URL 或发出错误的 URL

标签 java http url spring-mvc url-rewriting

我有一个 SpringMVC 应用程序,我不确定它是否正常工作。我有一个注册表单,网址为 http://localhost:8080/myapp/registration.htm 当我单击查询按钮时,应用程序被发布到 Controller ,用户被发布到第二个页面 getList.htm 显示结果列表,但是当发布到第二页时,网址仍然为 http://localhost:8080/myapp/registration.htm

当第二页发布时,用户应该返回到第一页http://localhost:8080/myapp/registration.htm 以显示从 getList 中选择的记录。 htm(显示多条记录)。

当用户被发回http://localhost:8080/myapp/registration.htm时,URL 为http://localhost:8080/myapp/getList/1985121244。 htm 其中 1985121244 是记录号。当用户返回首页后,URL 是否应该显示 http://localhost:8080/myapp/registration.htm

此外,如果用户在从 getList.htm POST 返回后尝试 POST 第一页,您会收到 HTTP 400 并且 URL 为 http://localhost:8080/myapp/getList/registration.htm。第二页附加到 URL,这不是 Controller 中的适当映射。有人可以解释一下这里发生了什么以及如何修复它。

已编辑

此外,当我第一次进入应用程序时,主菜单是 http://localhost:8080/myapp/hello.htm 当我单击 a href 时,我会进入注册页面,但是该页面显示但 url 不变。当从 hello.htm 页面单击 href 标签时, Controller 会请求获取注册页面并使用 return new ModelAndView("registration"); 返回它,我看到一些网站说我应该使用 return new ModelAndView("redirect:/registration"); 但是,当使用它时,我得到 404 Not Found - http://localhost:8080/myapp/registration" .任何人关于我在发布代码之前可以查看什么的任何想法我的代码很多

最佳答案

对我来说,您似乎只是在登录后返回 View 名称。当然,这不会改变你的网址。使用“redirect:/getList.htm”指向您需要的 url,而不是返回 View 名称。

然后处理 getList.htm 的 Controller 检查用户是否登录并返回正确的 View 名称。

关于java - Spring MVC Controller 更改 URL 或发出错误的 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15441138/

相关文章:

java - Gson解析为覆盖变量的子类

java - jSTL c :set to set a bean property results in argument type mismatch

javascript访问网络面板信息

asp.net-mvc - ASP.NET MVC Url.Action 将当前路由值添加到生成的 url

image - Tumblr 图片的 URL 模式是什么?

java 。带参数的 Singleton 和 getInstance

java - 为什么 fragment 中的 setVisibility 不起作用?

hibernate - 需要返回 Boolean @ResponseBody。现在收到 HTTP 406 错误

http - 在 Simperium 中创建每个用户的管理员 key

php - Ajax无限滚动和分页错误