第一个Servlet
来源:互联网 发布:fluke网络测试仪 编辑:程序博客网 时间:2024/06/14 18:34
1.先设置MyEclipse ,在windows-preferences-servers中设置tomcat服务器。tomcat默认用的是myeclipse中的jdk1.5,要改成1.6*注意要Enable,否则列表中依旧看不到
2.新建web project,文件中的WebRoot下有WEB-INF,就跟tomcat下的webapps一样,可以设置关联管理,deploy一下就直接布置好了
package com.occ;import java.io.IOException;import java.io.PrintWriter;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import java.util.*;public class MyFirstServlet extends HttpServlet {/** * The doGet method of the servlet. <br> * * This method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {response.setContentType("text/html");response.getWriter().write("now time: " + new Date().toLocaleString()+" ");PrintWriter out = response.getWriter();out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");out.println("<HTML>");out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");out.println(" <BODY>");out.print(" This is ");out.print(this.getClass());out.println(", using the GET method");out.println(" </BODY>");out.println("</HTML>");out.flush();out.close();}/** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {response.setContentType("text/html");PrintWriter out = response.getWriter();out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");out.println("<HTML>");out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");out.println(" <BODY>");out.print(" This is ");out.print(this.getClass());out.println(", using the POST method");out.println(" </BODY>");out.println("</HTML>");out.flush();out.close();}}
<img src="http://img.blog.csdn.net/20141230223523198?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemh1dGFvcmFu/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="" />
0 0
- Servlet(一)第一个Servlet
- 三、第一个Servlet
- 第一个Servlet
- 编写第一个servlet
- 三、第一个Servlet
- 第一个Servlet不容易
- 第一个Servlet应用
- 第一个servlet程序
- 第一个servlet程序
- 第一个Servlet程序
- 第一个Servlet程序
- 第一个Servlet程序
- Servlet 第一个DEMO
- 第一个servlet 程序
- 第一个Servlet
- 第一个servlet
- 第一个Servlet程序
- 第一个Servlet
- orcle 11g select count(*) from v$lock 引起的思索
- 使用 Sphinx 更好地进行 MySQL 搜索
- 如何学习JAVA
- [ Ubuntu Chinese Method ] uninstall DBus, install fcitx
- 兼职分享
- 第一个Servlet
- Dubbo之旅--架构路线
- 回顾2014,展望2015
- 利用CSS和<div>手绘静态多级菜单
- WPF动画之后属性值无法改变
- Cocos2d-x 跨平台特性分析
- C++学习笔记(第一章)
- asp.net中分页控件AspNetPager美化样式
- 操作控制台属性