最初に "/WEB-INF/views/searchResult.jsp"というビューに転送してから、Calculator.lookUp(Type、Place)をバックグラウンドで処理します。JSP - 最初にビューに転送し、その後バックグラウンドで処理メソッドを続行する方法?
現在、Calculator.lookUp(Type、Place)が最初に処理され、このメソッドが終了すると、ユーザーは「/WEB-INF/views/searchResult.jsp」に転送されます。 助けてくれてありがとう!
@WebServlet(urlPatterns="/search.do")
public class SrchServlet extends HttpServlet{
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String Type = request.getParameter("Type");
String Place = request.getParameter("Place");
request.setAttribute("Type", Type);
request.setAttribute("Place", Place);
//I want the forward to searchResult.jsp to occur
request.getRequestDispatcher("/WEB-INF/views/searchResult.jsp").forward(
request, response);
//and then in backend for the below method to run
Calculator.lookUp(Type, Place);
}
}
非同期要求によって、目的の結果が得られます。 [同期と非同期を理解する](https://www.javatpoint.com/understanding-synchronous-vs-asynchronous)を参照してください。 –
ありがとう、それは理にかなっていますが、私は上記の非同期要求コード。 – Padoga