欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Eclipse添加servlet模板过程代码详解

程序员文章站 2022-09-16 23:49:53
1.先写好一个servlet模板package com.exam.servlet;import java.io.ioexception;import javax.servlet.servletexce...

1.先写好一个servlet模板

package com.exam.servlet;

import java.io.ioexception;
import javax.servlet.servletexception;
import javax.servlet.http.httpservlet;
import javax.servlet.http.httpservletrequest;
import javax.servlet.http.httpservletresponse;

/**
 * datatime: 2020年7月15日 下午9:04:18
 * servlet implementation class dddd
 */
public class dddd extends httpservlet {
	private static final long serialversionuid = 1l;

	/**
	 * @see httpservlet#doget(httpservletrequest request, httpservletresponse response)
	 */
	protected void doget(httpservletrequest request, httpservletresponse response)
			throws servletexception, ioexception {
		// todo auto-generated method stub
		response.setcontenttype("text/html;charset=utf-8");
		request.setcharacterencoding("utf-8");
	}

	/**
	 * @see httpservlet#dopost(httpservletrequest request, httpservletresponse response)
	 */
	protected void dopost(httpservletrequest request, httpservletresponse response)
			throws servletexception, ioexception {
		// todo auto-generated method stub
		doget(request, response);
	}
}

2.添加到eclipse模板中

Eclipse添加servlet模板过程代码详解
Eclipse添加servlet模板过程代码详解
Eclipse添加servlet模板过程代码详解

再点击ok

应用并关闭

再打开的类中输入servlet按alt+/

就会输出当前的模板

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。