学习jsp(1)
我的开发环境是: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)的更多相关文章
- javaweb学习--jsp
阅读电子书<Java Web从入门到精通>密码:461c,学习JavaWeb基础知识.由于本人已有html基础,所以直接略过前面部分,进入jsp学习 jsp页面添加库引用,引入项目文件 引 ...
- 学习 JSP:第二步 创建一个JSP Web Project
接上文 学习 JSP:第一步Eclipse+Tomcat+jre(配置环境) [创建新工程](Dynamic Web Project) 1.选择 "File-->New-->Dy ...
- 学习JSP篇:jsp简单介绍
这几天开始学习JSP和Servlet,写些博客,记录自己的学习过程,算是自己从业开始的一个见证. 一.什么是JSP JSP的全称是Java Service Page,一种动态的网页开发技术,区别于静态 ...
- JavaWeb学习----JSP内置对象详解
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...
- JavaWeb学习----JSP脚本元素、指令元素、动作元素
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...
- JavaWeb学习----JSP简介及入门(含Eclipse for Java EE及Tomcat的配置)
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...
- 新手学习JSP+Servlet笔记一
作为一个新手,初次接触jsp,servlet,习惯了后台的开发,前台的知识一窍不通,利用闲暇时间,给自己补补,从MyEclipse开始. 安装好MyEclipse之后,没有安装程序的可以下载 http ...
- jsp学习--JSP运行原理,九大隐式对象和JSP常用标签
一.JSP运行原理 每个JSP 页面在第一次被访问时,WEB容器都会把请求交给JSP引擎(即一个Java程序)去处理.JSP引擎先将JSP翻译成一个_jspServlet(实质上也是一个servlet ...
- 学习jsp(3)
HttpServletRequest和HttpServletResponse: response.setContentType("text/html;charset=UTF-8") ...
- 学习jsp(2)
@Webservlet 具体见:http://www.cnblogs.com/luxh/archive/2012/06/06/2537458.html. 我折腾半天才发现,在web.xml里注册了,删 ...
随机推荐
- Java中的定时调度
Timer类是一个线程设施,用于实现在某个时间或者某一段时间后安排某个任务执行一次或者定期重复执行.需要与TimerTask配合使用. TimerTask类用来实现由Timer安排的一次或重复执行的某 ...
- 【转】UGUI实现unity摇杆
http://blog.csdn.net/onafioo/article/details/46403801 http://www.winig.cc/archives/348 好久没有写文章了,最近在做 ...
- jsp页面直接编写csss
<style> .logoZL{ width:550px; float:right; text-align:right; padding-right:15px; margin-right: ...
- 低功耗蓝牙4.0BLE编程-nrf51822开发(10)-描述符
特性中的属性有两种:属性值或描述符. 支持通知或指示的特性中默认有一个描述符:客户端特性配置描述符(Client Characteristic Configuration Descriptor,CCC ...
- git-svn
sudo apt-get install git-svn svn作为一个优秀源码版本的管理工具,可以适合绝大多数项目.但是因为它的采用中心化管理,不可避免的存在本地代码的备份和版本管理问题.也就是说对 ...
- isset和empty比较
PHP的isset()函数 一般用来检测变量是否设置 格式:bool isset ( mixed var [, mixed var [, ...]] ) 功能:检测变量是否设置 返回值: 若变量不存在 ...
- 在sublime中使用less
高亮显示: 可以在Less文件中显示语法高亮,这样看起来会更舒服一些. 按下Ctrl+Shift+P调出命令面板:输入install调出Install Package选项并回车:输入less,选中并安 ...
- (letcode)String to Integer (atoi)
Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. ...
- javac 错误: 编码GBK的不可映射字符
在java代码中有中文注释,使用javac编译时,出现编码报错. 错误: 编码GBK的不可映射字符 问题原因: 在编译的时候,如果我们没有用-encoding参数指定我们的JAVA源程序的编码格式,则 ...
- Exception not a valid month
oracle中的to_date('date','pattern') 其中的date和pattern格式应该要一样 SELECT to_date('2016-03-29 00:00:00','yyyy- ...