zoukankan      html  css  js  c++  java
  • 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
    

      

  • 相关阅读:
    Tomcat内存溢出的三种情况及解决办法分析
    详解:贝叶斯算法(bayesian)在GCMail反垃圾邮件系统中的应用
    关于solr schema.xml 和solrconfig.xml的解释
    Java流操作,InputStream、OutputStream及子类FileInputStream、FileOutputStream;BufferedInpu
    Introduce Null Object(引入Null对象)
    Solr Schema.xml和solrconfig.xml分析
    @InitBinder
    程序员修炼之道
    JSTL 标签库详细介绍资料
    Spring Mvc入门实例
  • 原文地址:https://www.cnblogs.com/WeWeZhang/p/6785098.html
Copyright © 2011-2022 走看看