- 浏览: 1474677 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (798)
- struts2 (42)
- servlet (20)
- quartz (4)
- jquery & ajax (24)
- tomcat (5)
- javascript (15)
- struts1 (8)
- 搜索关键字及链接 (3)
- fckeditor (3)
- Apache (5)
- spring (22)
- linux (3)
- 企业应用 (8)
- 综合应用 (13)
- 服务器 (2)
- 数据库 (85)
- 性能调优 (21)
- 网络应用 (15)
- 缓存技术 (8)
- 设计模式 (39)
- 面试题 (7)
- 程序人生&前辈程序员 (29)
- java基础 (59)
- hibernate (75)
- log4j (4)
- http (11)
- 架构设计 (28)
- 网页设计 (12)
- java邮件 (4)
- 相关工具 (11)
- ognl (7)
- 工作笔记 (18)
- 知识面扩展 (12)
- oracle异常 (1)
- 正则表达式 (2)
- java异常 (5)
- 项目实践&管理 (1)
- 专业术语 (11)
- 网站参考 (1)
- 论坛话题 (2)
- web应用 (11)
- cxf&webservice (22)
- freemarker (3)
- 开源项目 (9)
- eos (1)
- ibatis (6)
- 自定义标签 (3)
- jsp (3)
- 内部非公开文档(注意:保存为草稿) (0)
- 国内外知名企业 (2)
- 网店 (3)
- 分页 (1)
- 消费者习惯 (2)
- 每日关注 (1)
- 商业信息 (18)
- 关注商业网站 (1)
- 生活常识 (3)
- 新闻 (2)
- xml&JSON (5)
- solaris (1)
- apache.common (3)
- BLOB/CLOB (1)
- lucene (2)
- JMS (14)
- 社会进程 (8)
- SSH扩展 (2)
- 消费心理 (1)
- 珠三角 (1)
- 设计文档 (1)
- XWork&webwork (1)
- 软件工程 (3)
- 数据库及链接 (1)
- RMI (2)
- 国内外知名企业&人物 (1)
最新评论
-
司c马:
简介易懂、
OutputStream和InputStream的区别 -
在世界的中心呼喚愛:
解决我的问题
Java获取客户端的真实IP地址 -
bo_hai:
都是些基本的概念呀!
SSO -
tian_4238:
哥们,你也是搞水利这块的吧。
巧用SQLQuery中的addScalar -
loveEVERYday:
java.util.Date、java.sql.Date、java.sql.Time、java.sql.Timestamp小结
以下的简单 jsp-servlet 例子流程为:
index.jsp 提交一个 form 表单, tomcat 容器根据 form 中所定义的 action 从 web.xml 找到与之响应的 servlet : Hello.java ,根据 form 中定义的 method 找到 servlet 处理该请求的方法: doPost() ,调用该方法做一定的逻辑处理之后,跳转到另一个页面: result.jsp ;
以下为源码:
Hello.java
view plaincopy to clipboardprint?
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Hello extends HttpServlet {
/**
* Constructor of the object.
*/
public Hello() {
super();
System.out.println("new Hello");
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
System.out.println("destroy");
}
/**
* 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 {
String text1 = request.getParameter("text1");
String str = text1;
response.sendRedirect("result.jsp?text1=" + text1);
}
/**
* 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 {
doGet(request,response);
}
/**
* Initialization of the servlet. <br>
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
System.out.println("init");
}
}
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Hello extends HttpServlet {
/**
* Constructor of the object.
*/
public Hello() {
super();
System.out.println("new Hello");
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
System.out.println("destroy");
}
/**
* 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 {
String text1 = request.getParameter("text1");
String str = text1;
response.sendRedirect("result.jsp?text1=" + text1);
}
/**
* 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 {
doGet(request,response);
}
/**
* Initialization of the servlet. <br>
* @throws ServletException if an error occure
*/
public void init() throws ServletException {
// Put your code here
System.out.println("init");
}
}
index.jsp
view plaincopy to clipboardprint?
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>hello</title>
</head>
<body>
<form action="myForm" method="post">
<input type="text" name="text1" value="China">
<input type="submit" value="submit myForm">
</form>
</body>
</html>
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>hello</title>
</head>
<body>
<form action="myForm" method="post">
<input type="text" name="text1" value="China">
<input type="submit" value="submit myForm">
</form>
</body>
</html>
result.jsp
view plaincopy to clipboardprint?
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>result</title>
</head>
<body>
hello: <%= request.getParameter("text1") %>
</body>
</html>
<%@ page language="java" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>result</title>
</head>
<body>
hello: <%= request.getParameter("text1") %>
</body>
</html>
web.xml
view plaincopy to clipboardprint?
<?xml version="1.0" encoding="utf-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>hello</servlet-name>
<servlet-class>Hello</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>hello</servlet-name>
<url-pattern>/myForm</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
发表评论
-
ServletContext接口
2011-08-03 19:57 13121. 获取web应用(tomcat的Context ... -
ServletConfig接口
2011-08-03 19:41 13441. ServletConfig接口用于描述Ser ... -
HttpServletResponse
2011-08-03 19:31 17861. 控制消息头 add ... -
基于AOP设计思想的拦截器(Interceptor)与传统拦截器(Filter)的区别
2011-07-11 11:46 9367现在AOP的设计开发理念在软件开发中用的越来越广泛,在我们开发 ... -
HttpSessionListener用法
2010-12-02 20:46 1475继上次说到Listener的功效,这里就不得不说说另外一个接口 ... -
过滤器(filter)在web 中的应用(二)
2010-06-25 16:42 1082Filters是在请求资源(Servl ... -
web.xml 中的listener、 filter、servlet 加载顺序及其详解(2)
2010-06-25 13:56 159122、配置Struts <dis ... -
web.xml 中的listener、 filter、servlet 加载顺序及其详解(1)
2010-06-25 13:46 2828在项目中总会遇到一 ... -
web.xml中context-param,listener,filter,servlet加载顺序
2010-06-25 13:35 1858不同类别加载顺序:先 context-param 然后 lis ... -
过滤器(filter)在web 中的应用(一)
2010-06-22 17:38 2056过滤器(Filter)在Web开发中的应用: Filter是 ... -
javax.servlet基本类和接口
2010-06-19 21:25 2111基本类和接口一、javax.servlet.Servlet ... -
Session机制详解(jsp-servlet 技术)
2010-06-17 20:51 1440虽然session机制在web应用程序中被采用已经很长时间 ... -
servlet中配置文件web.xml中的参数context-param和init-param区
2010-06-17 09:56 1817web.xml里面可以定义两种参数:(1)applicatio ... -
优化Servlet配置为web.xml瘦身
2010-06-17 09:46 1716本文介绍优化Servlet配置为web.xml瘦身,web.x ... -
Java中用Servlet Listener实现定时监听
2010-06-12 13:50 1506分两步走: (1)实现 javax.servlet. ... -
戏说java web开发中的listener和filter
2010-06-12 11:26 1563今天在公司看到有同事在写filter,晚上一个人在家无聊,就想 ... -
谈谈Listener Servlet的应用
2010-06-12 10:53 1223... -
web中的listener简介
2010-06-12 10:42 1305... -
利用HttpSessionListener实现网站在线人数统计功能
2010-06-12 10:17 2029在网站中经常需要进行在线人数的统计。过去的一般做法是结合登录 ...
相关推荐
一个最简单Jsp-Servlet的MVC架构例子,适合初学者。带数据库脚本和全部jar。适合初学者理解MVC架构。
jsp servlet 上传例子 jspsmartupload jsp servlet 上传例子 jspsmartupload jsp servlet 上传例子 jspsmartupload
一个简单的JSP+Servlet图片上传例子
jsp-servlet入门比较全面,里面有一些简单的例子及学习练习
jsp/servlet学习例子(完整项目带数据库)
这是一个以JSP、servlet、JavaBean实现MVC三层架构的简单例子,使用XML作为数据库连接的配置文件。 使用环境:eclipse_3.2、myeclipse_5.1、jdk_6.0、tomcat_5.5、sql server 2005 <br>----------------------...
jsp+servlet+bean+mysql例子,供初学javaweb的同学参考。
jsp+servlet+javabean登录小例子
这个工程是个例子,主要运用jsp 和servlet.其中利用到了反射来动态加载servlet.有点像struts框架的样子
这是一个用MVC开发的例子,对初学者有很到的帮助啊 ,说说没用看了知道
该例子是一个简单的MVC的小例子,通过JSP+Servlet+JavaBean来完成,并且里面用到了封装以及集合类。非常适合初学者,快速掌握MVC框架.
这是用jsp和servlet做的一个小工程,里面涉及数据库的增删改查。功能有注册和登录等。适合JSP和Servlet的初学者。附带数据库文件,SQL Server的数据库文件。
简单的jsp servlet例子 mysql数据库 望笑纳
jsp+servlet写的一个crud(增删改查)培训的例子,链接的数据库是sqlserver
一个关于 jsp+servlet+javaBean ,采用mvc model2的模式开发 并且带分页。
jsp servlet构建的登录注册例子,jsp负责视图部分,含少量Java代码,servlet负责页面跳转,参数传递,调用数据库类(Dbutil.java)进行插入,查询用户操作。
JavaServletAPI提供了一个简单的接口,通过这个接口,Servlet引擎可以有效地跟踪用户的会话。 建立Session 因为HTTP是一个请求-响应协议,一个会话在客户机加入之前会被认为是一个新的会话。加入的意思是返回会话...
jsp+servlet+javabean实现登录例子
初级入门的JSP小例子。用servlet实现的网上书城的小功能。
采用JSP+ Servlet + JDBC做的一个简单的例子。能够完成基本的 对多表的 增,删 ,改,查,分页。。