我有2個servlet,「HomeController」和「SearchController」。在針對home.jsp我有了一個搜索框,並提交行動「搜索」Java servlet不派發到另一個servlet
<form action="Search" method="post" name="searchForm">
當所以SearchController做的第一件事是一個表格:
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
if (!validator.isValidAlphaOnly(request.getParameter("breed"))) {
request.setAttribute("error", "Breed search term invalid. Enter only letters");
RequestDispatcher requestVar = request.getRequestDispatcher("/Home");
requestVar.forward(request, response);
} else {
processRequest(request, response);
}
}
不同的是不去到/ home,即使我有映射如下:
<servlet>
<servlet-name>HomeController</servlet-name>
<servlet-class>Controllers.HomeController</servlet-class>
</servlet>
<servlet>
<servlet-name>SearchController</servlet-name>
<servlet-class>Controllers.SearchController</servlet-class>
</servlet>
<servlet>
<servlet-name>DogController</servlet-name>
<servlet-class>Controllers.DogController</servlet-class>
</servlet>
<servlet>
<servlet-name>LogoutController</servlet-name>
<servlet-class>Controllers.LogoutController</servlet-class>
</servlet>
<servlet>
<servlet-name>UpdateController</servlet-name>
<servlet-class>Controllers.UpdateController</servlet-class>
</servlet>
<servlet>
<servlet-name>AddController</servlet-name>
<servlet-class>Controllers.AddController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>SearchController</servlet-name>
<url-pattern>/Search</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LogoutController</servlet-name>
<url-pattern>/Logout</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>UpdateController</servlet-name>
<url-pattern>/Update</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>AddController</servlet-name>
<url-pattern>/Add</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DogController</servlet-name>
<url-pattern>/Dog/View/*</url-pattern>
<url-pattern>/Dog/Edit/*</url-pattern>
<url-pattern>/Dog/Add</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>HomeController</servlet-name>
<url-pattern>/Home</url-pattern>
<url-pattern>/</url-pattern>
</servlet-mapping>
你的if條件執行了嗎?它只有在搜索詞不是純字母表時纔會執行。 – asgs 2011-06-01 19:15:42
是的條件執行 – Sara 2011-06-01 19:21:05
爲什麼不遠程調試應用程序,因爲它在應用程序服務器上運行,並檢查post方法中發生了什麼(例如,是否真的在執行應該執行調度程序的代碼塊?認爲它應該這樣做...等)? – 2011-10-17 10:27:22