我刚刚开始使用Servlets并设法使用一些servlet作为单独的URL来填充数据库以进行一些虚拟测试.形式的东西:
public class Populate_ServletName extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/plain");
//Insert records
//Print confirmation
}
}
Run Code Online (Sandbox Code Playgroud)
我有大约6个这样的servlet,我想按顺序执行.我正在考虑使用setLocation来设置要重定向的下一页,但不确定这是否是正确的方法,因为重定向应该在插入记录之后发生.具体来说,我正在寻找这样的东西:
public class Populate_ALL extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
resp.setContentType("text/plain");
//Call Populate_1
//Call Populate_2
//Call Populate_3
//...
}
}
Run Code Online (Sandbox Code Playgroud)
有什么建议?