慕码人2483693
jsp要调用servlet中自定义的方法需要把自定的方法放在doPost或者doGet或者init方法中。举例如下:import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;public class HelloWorldServlet extends HttpServlet {@Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {// TODO Auto-generated method stubsuper.doGet(req, resp);System.out.println("doGet");}@Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {// TODO Auto-generated method stubsuper.doPost(req, resp);//调用自定义方法returnBack(req,resp);System.out.println("doPost");}//这里是自定义方法public void returnBack(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException{System.out.println("really!go home");}}