[英]is redirecting from one jsp to another jsp bad practice? And if yes why?
我剛剛開始學習Java Web編程,並且在一些網站和資源上我已經讀到,從一個JSP重定向到另一個JSP是不好的做法。 例如,我的代碼是這樣的:
<form>
<body>
<button name="nameButton">Button</button>
<%
String stringButton = request.getParameter("nameButton");
if(stringButton != null){
response.sendRedirect("anotherJSPFile.jsp");
}
%>
</body>
</form>
它工作正常,但是我不想顯得業余,學習更好的方法,所以有什么建議嗎?
在JSP文件中編寫Java代碼不是一種好習慣。 將重定向邏輯移至服務。 遵循一些標准的設計模式,例如MVC,並分離模型,視圖,控制器。
將來將易於維護。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.