Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
CS381 - Lab Session 5 
 
 
 
A. Creating a ‘Hello world’ servlet 
 
1. Using “nedit” or “notepad” or your tool of choice, create the following servlet: 
 
package webtech; 
 
import java.io.*; 
import javax.servlet.*; 
import javax.servlet.http.*; 
 
/** a simple servlet */ 
 
public class HelloWorld extends HttpServlet { 
 
  public void doGet(HttpServletRequest request, 
                    HttpServletResponse response) 
     throws ServletException, IOException { 
 
    response.setContentType(“text/html”); 
    PrintWriter out = response.getWriter(); 
    String docType =  
      “\n”; 
    out.println(docType + 
      “\n” + 
      “Servlet example\n” + 
“

Hello world

\n” + “”); } } 2. Save as HelloWorld.java within the appropriate directory, (i.e. tomcat/webapps/webtech/WEB-INF/classes/webtech) 3. Compile the servlet you just created (i.e. cd into tomcat/webapps/webtech/WEB-INF/classes and then run javac webtech/HelloWorld.java) 4. Open the page in your browser (e.g. http://workstation01.ee.surrey.ac.uk:49999/webtech/servlet/webtech.HelloWor ld) B. Reading three parameters 1. Using “nedit” or “notepad” or your tool of choice, create a new text file, and add the required HTML elements (you could use the following HTML file). Collecting three parameters

Collecting three parameters

First Parameter:
Second Parameter:
Third Parameter:
2. Save as ThreeParams.html in the appropriate directory (i.e. tomcat/webapps/webtech) 3. Create a servlet called ThreeParams.java that reads the form parameters param1, param2 and param3 and places their values in a bulleted list 4. Use request.getParameter(“param1”) to read the first parameter. Similarly, for the other two. 5. Display the values of the three parameters in the HTML page, using the out.println() method. 6. Compile the servlet you just created (i.e. cd into tomcat/webapps/webtech/WEB-INF/classes and then run javac webtech/ThreeParams.java 7. Open the page in your browser (e.g. http://workstation01.ee.surrey.ac.uk:49999/webtech/ThreeParams.html)