在 servlet 中使用命令只是从一个页面重定向到另一个页面是否正常?
我使用 MVC 模式,我的 servlet 帮助我处理请求并给我一个新的页面路径。如果我只想使用 servlet 从一个页面重定向到另一个页面怎么办?可以吗,还是我应该使用常规链接重定向?
I use MVC pattern and my servlet serves me to process the request and give me a new page path to go. What if I just want to redirect from one page to another using servlet? Would it be ok or I should just use regular link redirecting?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你的意思是,先POST,然后重定向?如果您不发送任何数据,这就没有意义。只需将其设置为普通的 GET 链接,并在必要时让 servlet 对
doGet()
进行预处理即可。优点是它可以添加书签并且有利于 SEO。You mean, first POST and then redirect? This makes not really sense if you aren't sending any data. Just make it a normal GET link and let the servlet if necessary do the preprocessing on
doGet()
. The advantage is that it's bookmarkable and SEO-friendly.如果您没有其他任务要做,只需重定向,那么您就不需要 servlet - 简单的 GET 链接就可以了。
但如果你有一些业务处理,最好将这种工作委托给Servlet(控制器)。处理完成后,Servlet 将重定向(分派)到另一个 .JSP(视图)。
应该是GET还是POST?这取决于您想要传递什么数据。
If you don't have additional tasks to do, only redirecting then you don't need a servlet - the simple GET link is OK.
But if you have some business processing, it would be better to delegate this kind of job to Servlet (controller). After the processing, the Servlet will redirecting (dispatching) to another .JSP (view).
Should be GET or POST? This depends what data you want to pass.