简体   繁体   中英

Is it normal to use commands in servlet just to redirect from one page to another?

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?

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM