servlet

/*jadclipse*/// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.

package javax.servlet.annotation;

import java.lang.annotation.Annotation;

// Referenced classes of package javax.servlet.annotation:
//            WebInitParam

public interface WebServlet
    extends Annotation
{

    public abstract String name();

    public abstract String[] value();

    public abstract String[] urlPatterns();

    public abstract int loadOnStartup();

    public abstract WebInitParam[] initParams();

    public abstract boolean asyncSupported();

    public abstract String smallIcon();

    public abstract String largeIcon();

    public abstract String description();

    public abstract String displayName();
}

sevlet 生命周期

1、创建一个web工程

2、创建测试sevlet,把默认方法都选中就好了,等下看下就知道生命周期了。

 

 

package test;

import java.io.IOException;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class TestServlet
 * 
 * @author ZengWenFeng
 */
@WebServlet(description = "TestServlet", urlPatterns = {"/TestServlet"})
public class TestServlet extends HttpServlet
{
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public TestServlet()
	{
		super();
		
		System.out.println("TestServlet()");
	}

	/**
	 * @see Servlet#init(ServletConfig)
	 */
	public void init(ServletConfig config) throws ServletException
	{
		System.out.println("init");
	}

	/**
	 * @see Servlet#destroy()
	 */
	public void destroy()
	{
		System.out.println("destroy");
	}

	/**
	 * @see Servlet#getServletConfig()
	 */
	public ServletConfig getServletConfig()
	{
		return null;
	}

	/**
	 * @see Servlet#getServletInfo()
	 */
	public String getServletInfo()
	{
		return null;
	}

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
//	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
//	{
//		System.out.println("service");
//	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		String username = (String)request.getParameter("username");
		String password = (String)request.getParameter("password");
		
		System.out.println(username);
		System.out.println(password);
		System.out.println("doGet");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		System.out.println("doPost");
	}

	/**
	 * @see HttpServlet#doPut(HttpServletRequest, HttpServletResponse)
	 */
	protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doDelete(HttpServletRequest, HttpServletResponse)
	 */
	protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doHead(HttpServletRequest, HttpServletResponse)
	 */
	protected void doHead(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doOptions(HttpServletRequest, HttpServletResponse)
	 */
	protected void doOptions(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		// TODO Auto-generated method stub
	}

	/**
	 * @see HttpServlet#doTrace(HttpServletRequest, HttpServletResponse)
	 */
	protected void doTrace(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
	{
		// TODO Auto-generated method stub
	}

}

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form action="TestServlet">
		username:<input type="text" name="username"></input>
		<br>
		password:<input type="password" name="password"></input>
		<br>
		<input type="submit"></input>
	</form>
</body>
</html>

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>PrjServlet</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
</web-app>

http://127.0.0.1:8089/PrjServlet/index.html


2011-5-16 9:04:55 org.apache.tomcat.util.digester.SetPropertiesRule begin
警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:PrjServlet' did not find a matching property.
2011-5-16 9:04:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Server version:        Apache Tomcat/5.5.30
2011-5-16 9:04:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Server built:          Jun 30 2015 08:08:33 UTC
2011-5-16 9:04:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Server number:         5.5.30.0
2011-5-16 9:04:55 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Name:               Windows 7
2011-5-16 9:04:55 org.apache.catalina.startup.VersionLoggerListener log
信息: OS Version:            6.1
2011-5-16 9:04:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Architecture:          amd64
2011-5-16 9:04:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Java Home:             D:\Java\JRE
2011-5-16 9:04:55 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Version:           1.6.0_45-b06
2011-5-16 9:04:55 org.apache.catalina.startup.VersionLoggerListener log
信息: JVM Vendor:            Sun Microsystems Inc.
2011-5-16 9:04:55 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_BASE:         D:\apache-tomcat-5.5.30
2011-5-16 9:04:55 org.apache.catalina.startup.VersionLoggerListener log
信息: CATALINA_HOME:         D:\apache-tomcat-5.5.30
2011-5-16 9:04:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:64513
2011-5-16 9:04:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.base=D:\apache-tomcat-5.5.30
2011-5-16 9:04:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dcatalina.home=D:\apache-tomcat-5.5.30
2011-5-16 9:04:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dwtp.deploy=D:\apache-tomcat-5.5.30\webapps
2011-5-16 9:04:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Djava.endorsed.dirs=D:\apache-tomcat-5.5.30\endorsed
2011-5-16 9:04:55 org.apache.catalina.startup.VersionLoggerListener log
信息: Command line argument: -Dfile.encoding=UTF-8
2011-5-16 9:04:55 org.apache.catalina.core.AprLifecycleListener lifecycleEvent
信息: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\Java\JRE\bin;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;D:\Java\JRE\bin;D:\Java\JDK\bin;D:\Java\JDK\jre\bin;D:\Maven3.2.1\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Microsoft SQL Server\90\Tools\binn\;.
2011-5-16 9:04:55 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["http-bio-8089"]
2011-5-16 9:04:55 org.apache.coyote.AbstractProtocol init
信息: Initializing ProtocolHandler ["ajp-bio-8009"]
2011-5-16 9:04:55 org.apache.catalina.startup.Catalina load
信息: Initialization processed in 447 ms
2011-5-16 9:04:55 org.apache.catalina.core.StandardService startInternal
信息: Starting service Catalina
2011-5-16 9:04:55 org.apache.catalina.core.StandardEngine startInternal
信息: Starting Servlet Engine: Apache Tomcat/5.5.30
2011-5-16 9:04:55 org.apache.tomcat.websocket.server.WsSci onStartup
信息: JSR 356 WebSocket (Java WebSocket 1.1) support is not available when running on Java 6. To suppress this message, run Tomcat on Java 7, remove the WebSocket JARs from $CATALINA_HOME/lib or add the WebSocket JARs to the tomcat.util.scan.DefaultJarScanner.jarsToSkip property in $CATALINA_BASE/conf/catalina.properties. Note that the deprecated Tomcat 7 WebSocket API will be available. 
2011-5-16 9:04:55 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deploying web application directory D:\apache-tomcat-5.5.30\webapps\ROOT
2011-5-16 9:04:56 org.apache.catalina.startup.HostConfig deployDirectory
信息: Deployment of web application directory D:\apache-tomcat-5.5.30\webapps\ROOT has finished in 44 ms
2011-5-16 9:04:56 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["http-bio-8089"]
2011-5-16 9:04:56 org.apache.coyote.AbstractProtocol start
信息: Starting ProtocolHandler ["ajp-bio-8009"]
2011-5-16 9:04:56 org.apache.catalina.startup.Catalina start
信息: Server startup in 418 ms
TestServlet()
init
service
2011-5-16 9:06:16 org.apache.catalina.core.StandardContext reload
信息: Reloading Context with name [/PrjServlet] has started
destroy
2011-5-16 9:06:22 org.apache.catalina.core.StandardContext reload
信息: Reloading Context with name [/PrjServlet] is completed




TestServlet()
init
username
password
doGet

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

spencer_tseng

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值