我的开发环境是:jdk1.7;netbean ;tomcat7.

尝试着写了第一个程序:

ublic class myServlet extends HttpServlet{
    @Override
    protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out=response.getWriter();
        out.println("<html>");
        out.println("<head>");
        out.println("<title>hello,my frst jsp</title>");
        out.println("<body>");
        out.println("<h1>"+new java.util.Date()+"</h1>");
        out.println("</body>");
    }

public class NewServlet extends HttpServlet {

/**
     * Processes requests for both HTTP
     * <code>GET</code> and
     * <code>POST</code> methods.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            /* TODO output your page here. You may use following sample code. */
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet NewServlet</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet NewServlet at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        } finally {            
            out.close();
        }
    }

// <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP
     * <code>GET</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

/**
     * Handles the HTTP
     * <code>POST</code> method.
     *
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

/**
     * Returns a short description of the servlet.
     *
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>
}

学习jsp(1)的更多相关文章

  1. javaweb学习--jsp

    阅读电子书<Java Web从入门到精通>密码:461c,学习JavaWeb基础知识.由于本人已有html基础,所以直接略过前面部分,进入jsp学习 jsp页面添加库引用,引入项目文件 引 ...

  2. 学习 JSP:第二步 创建一个JSP Web Project

    接上文 学习 JSP:第一步Eclipse+Tomcat+jre(配置环境) [创建新工程](Dynamic Web Project) 1.选择 "File-->New-->Dy ...

  3. 学习JSP篇:jsp简单介绍

    这几天开始学习JSP和Servlet,写些博客,记录自己的学习过程,算是自己从业开始的一个见证. 一.什么是JSP JSP的全称是Java Service Page,一种动态的网页开发技术,区别于静态 ...

  4. JavaWeb学习----JSP内置对象详解

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...

  5. JavaWeb学习----JSP脚本元素、指令元素、动作元素

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...

  6. JavaWeb学习----JSP简介及入门(含Eclipse for Java EE及Tomcat的配置)

    ​[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...

  7. 新手学习JSP+Servlet笔记一

    作为一个新手,初次接触jsp,servlet,习惯了后台的开发,前台的知识一窍不通,利用闲暇时间,给自己补补,从MyEclipse开始. 安装好MyEclipse之后,没有安装程序的可以下载 http ...

  8. jsp学习--JSP运行原理,九大隐式对象和JSP常用标签

    一.JSP运行原理 每个JSP 页面在第一次被访问时,WEB容器都会把请求交给JSP引擎(即一个Java程序)去处理.JSP引擎先将JSP翻译成一个_jspServlet(实质上也是一个servlet ...

  9. 学习jsp(3)

    HttpServletRequest和HttpServletResponse: response.setContentType("text/html;charset=UTF-8") ...

  10. 学习jsp(2)

    @Webservlet 具体见:http://www.cnblogs.com/luxh/archive/2012/06/06/2537458.html. 我折腾半天才发现,在web.xml里注册了,删 ...

随机推荐

  1. 去除GHOST版系统自带的2345流氓软件

    话说2345真心流氓  用户想用你 自然不会删你 你这样强制性的 反而引起反感 应该是软件劫持性的捆绑 所以非常难起清除 最方便的方法就是 下载个 黄山IE修复专家   先把IE修复好 然后删除预安装 ...

  2. Rochester Memory Hardware Error Research Project

    http://www.cs.rochester.edu/research/os/memerror/

  3. include pointers as a primitive data type

    Computer Science An Overview _J. Glenn Brookshear _11th Edition Many modern programming languages in ...

  4. 以大写字母“J”来展示位图

    '0' => '00011100001111111001100011011000001111000001111000001111000001111000001111000001111000001 ...

  5. Class Abstraction -- Object Interfaces

    <?php /* PHP 5 introduces abstract classes and methods. Classes defined as abstract may not be in ...

  6. MySql解决插入中文乱码问题

    在dos中登陆mysql 后输入: // 查看数据使用的所有编码show variables like 'character%';// 修改客户端的编码 为 gbkset character_set_ ...

  7. 【nodejs】使用Node.js实现REST Client调用REST API

    最近在产品中开发基于REST的API接口,结合自己最近对Node.js的研究,想基于它开发一个REST Client做测试之用. 通过初步研究,Node.js开发HTTP Client还是挺方便的. ...

  8. php源码安装

    要用swoole,首先需要有PHP环境.由于swoole的某些特性,最好是能够从源码编译安装PHP,这样在使用过程中可以避免很多不必要的错误.PHP下载地址:http://php.net/在这里挑选你 ...

  9. Redis学习笔记(4)-List

    package cn.com; import java.util.List; import redis.clients.jedis.Jedis; import redis.clients.jedis. ...

  10. NSURL基本操作示例说明

    http://blog.csdn.net/zhibudefeng/article/details/7920686