Develop debugging servlet (2) with JBuilder
Huang Wei, Lu Bowi
5. Write the servlet code after the above settings, we can start writing a servlet code. JBuilder provides Servlet Wizard for the development of servlets, which can be set via the tool to set the parameters of the servlet, and the implemented HTTP function. The steps to add a servlet to the project are as follows: (1) Select New from the FILE menu, and select Servlet; (2) Generate a non-parameter using servlet wizard, only service () Helloservlet; (3) in Service ( The following code is added. When the client calls Helloservlet, the Helloservlet returns information to the client "Hello, World". public void service (HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {res.setContentType ( "text / html"); ServletOutputStream out = res.getOutputStream (); out.println ( ""); out.println ( "
8. Debug servlet If servlet is developed in strict accordance with the above steps, the servlet will be very easy in JBuilder: (1) End the operation of the program in step 7 (press Ctrl C) in the DOS window; (2) in Helloservlet In the middle of the breakpoint, for example, Res.SetContentType ("text / html") in Service (); (3) Run menu Run | Debug 'myclass1'; (4) Start the browser, type "http: // 192.168.0.9:8020/Servlet/hiservlet "; (5) This time the program will return to jBuilder, the debugger stays in Res.SetContentType (" text / html "); Figure 1 Figure 2