一个关于GenericServlet的问题

zhaoyan 2001-09-20 02:36:29
这里有段程序
public class HelloServlet extends GenericServlet
{
String initString;
public void init(ServletConfig config) throws GenerletException)
{ super.init(config);
initString=new String("I have been initialized");
}
public void service(ServletRequest req,ServletResponse res)
throws ServletException, IOException
{
Date today =new Date();
ServletOutputStream out=res.getOutputStream();
out.println("HELLO WORLD");
out.println(today.toString());
out.println(getServletInfo());
}

public void Destroy()
{
}
public String getServletInfo()
{
return"HELLO WORLD";
}


方法init是做什么用处的啊?还有Service方法是什么用处?
我是刚学JAVA的初学者,请多多指教,最好能每行解释一下。
...全文
92 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
leizhengdeng 2001-09-20
  • 打赏
  • 举报
回复
init作些初始化的工作,如与数据库连接等等。
Service就是处理request和发出response

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧