ff

/**
 * Servlet
 */
sun公司提供的开发动态web资源的Java类
交互式地浏览和修改数据,生成动态Web内容
运行环境是服务器环境
接收请求
完成响应
/**
 * 新建Servlet项目
 */
Package
New
Web Project
New
Class
cn.wewezhang.weServlet
package cn.wewezhang.weServlet;
import java.io.IOException;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class WeServlet implements Servlet{
	@Override
	public void init(ServletConfig arg0) throws ServletException {
		System.out.print("WeServlet - init");
	}
	@Override
	public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException {
		System.out.print("WeServlet - service");
		arg1.getWriter().write("写点什么好呢");
	}
	@Override
	public void destroy() {
		System.out.print("WeServlet - destroy");
	}
	@Override
	public ServletConfig getServletConfig() {
		// TODO Auto-generated method stub
		return null;
	}
	@Override
	public String getServletInfo() {
		// TODO Auto-generated method stub
		return null;
	}
}
//web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www/w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    version="2.5">
    
    <!-- 注册Servlet名称 -->
    <servlet>
    	<servlet-name>WeServlet</servlet-name>
    	<servlet-class>cn.wewezhang.weServlet</servlet-class>
    </servlet>
    
    <!-- Servlet的路径 -->
    <servlet-mapping>
    	<servlet-name>WeServlet</servlet-name>
    	<url-pattern>/WeServlet</url-pattern>
    </servlet-mapping>
    
    
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list> 
</web-app>
//
http://localhost:8080/WeServlet/WeServlet

  

posted @ 2017-04-29 14:07  WeWeZhang  阅读(154)  评论(0编辑  收藏  举报