我在JSP中相當新,我需要一些幫助。在index.jsp加載之前調用控制器
我有一個index.jsp文件,顯然如果你輸入「localhost //」,它會默認自動調用index.jsp。我想知道這是如何工作的,因爲我打算在index.jsp加載之前先調用控制器。
雖然我試着解決它。在我的index.jsp,我把那裏是這樣的:
if(request.getParameter("submit") == null &&
request.getAttribute("submit") == null){
response.sendRedirect("getInformation");
}
在這裏,我強迫的index.jsp直接調用我的控制器/ servlet的。 (我用@ WebServlet(「/ getInformation」在我想調用的控制器上)
我想知道是否有更好的方法來做到這一點,因爲我希望我的控制器/ servlet上的所有邏輯代碼以及所有html代碼儘可能多。
你要什麼在控制呢?如果你分享這個,我想你會得到更好的方法。 – Apurv