Java WEB之Servlet学习之路(一)一个最简单的Servlet应用

   好久没有更新博客了,有点冷清,主要是最近忙着看Java WEb前段时间都是基础,一些http理论和WEB容器理论,没有什么实践性代码,所以没写代码,现在终于正式开始Servlet编程了,下面就得好好的开始写代码了呃,下面奉上第一篇,Setblet的Hello World!!!

首先放上Setvlett代码

package com.bird.servlet;

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

public class ServletDemo2 extends HttpServlet {

	
	private static final long serialVersionUID = 1L;

	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		response.getOutputStream().write("Bird".getBytes());
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		
	}

}

下面是相对应的Web.xml的配置文件的代码

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
	xmlns="http://java.sun.com/xml/ns/j2ee" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
	http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
	
	<servlet>
	<servlet-name>ServletDemo</servlet-name>
	<servlet-class>com.bird.servlet.ServletDemo</servlet-class>
	</servlet>
  <servlet>
    <servlet-name>ServletDemo2</servlet-name>
    <servlet-class>com.bird.servlet.ServletDemo2</servlet-class>
  </servlet>
 
	
	<servlet-mapping>
	<servlet-name>ServletDemo</servlet-name>
	<url-pattern>/ServletDemo</url-pattern>
	</servlet-mapping>
  <servlet-mapping>
    <servlet-name>ServletDemo2</servlet-name>
    <url-pattern>/servlet/ServletDemo2</url-pattern>
  </servlet-mapping>
 
 
 
  
	
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

这样的话,在Eclipse中就可以装载一个Tomcat运行了,呵呵,简单吧,,。,,,,淡定

你可能感兴趣的:(java,eclipse,tomcat,Web,servlet,encoding)