教程2:简单servlet程序实现

1工程src文件夹,new java package,com.aa.servlet

2new java class

~~~~~~~~~~~~~~~~~~~~~~~~~

package com.hyh.servlet;
import java.io.IOException;
import java.io.PrintWriter;


import javax.servlet.ServletException;
import javax.servlet.http.*;
public class HelloServlet extends HttpServlet
{
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
resp.setContentType("text/html");

PrintWriter out=resp.getWriter();
out.println("<html><head><title>Hello world!</title></head>");
out.println("<body>hahaha hello world</body></html>");
out.flush();


}
}


~~~~~~~~~~~~~~~~~~~~~~~~~~~

修改web.xml

<servlet>
 <servlet-name>Helloworld</servlet-name>
 <servlet-class>com.hyh.servlet.HelloServlet</servlet-class>
 </servlet>
 
 <servlet-mapping>
<servlet-name>Helloworld</servlet-name>
<url-pattern>/aaa</url-pattern> 
 </servlet-mapping>

~~~~~~~~~~~~~~~~~

访问http://localhost:8080/test/aaa

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试