6月 10

1,下载配置JDK

2,下载配置Eclipse

3,下载配置Tomcat

src下创建jsp.servlet的package

建立HelloServlet.java文件

package jsp.servlet;
    
import java.io.*;
    
import javax.servlet.http.*;
    
public class HelloServlet extends HttpServlet {
        
        
        
    public void doGet(HttpServletRequest request, 
            HttpServletResponse response) throws IOException{
            
        PrintWriter out = response.getWriter();
        out.write("Hello World!");
    }
}

WebContent下WEB-INF中添加web.xml文件

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
  
    <servlet>
        <servlet-name>HelloServlet</servlet-name>
        <servlet-class>jsp.servlet.HelloServlet</servlet-class>
    </servlet>
      
    <servlet-mapping>
        <servlet-name>HelloServlet</servlet-name>
        <url-pattern>/HelloServlet</url-pattern>
    </servlet-mapping> 
       
</web-app>

启动 tomcat

browser中键入http://localhost:8080/OceanWeb/HelloServlet即可

written by ocean