Servlet初试

1.eclipse新建动态web项目

2.src下面新建MyFirstServlet类,让其继承Servlet

Servlet初试_第1张图片

3 修改service方法

package com.dxm.servlet;

import java.io.IOException;

import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletResponse;

public class MyFirstServlet implements Servlet {
	
	public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException {
		HttpServletResponse resonse = (HttpServletResponse)arg1;
		resonse.getWriter().write("this is my first servlet");
	}

	public void destroy() {
		// TODO Auto-generated method stub
		
	}

	public ServletConfig getServletConfig() {
		// TODO Auto-generated method stub
		return null;
	}

	public String getServletInfo() {
		// TODO Auto-generated method stub
		return null;
	}

	public void init(ServletConfig arg0) throws ServletException {
		// TODO Auto-generated method stub
		
	}

	

}

4 修改项目的web.xml文件,增加下面的配置

Servlet初试_第2张图片

5 发布,运行tomcat

6 访问http://localhost:8080/WEB0912/first

Servlet初试_第3张图片 

你可能感兴趣的:(JAVA)