 Java 应用与开发 - Servlet 编程内,由 Web 容器负责它的对象的创建和销毁,不能直接由 其它类对象来调用。 ▶ 当 Web 容器接收到对它的 HTTP 请求时,自动创建 Servlet 对象,并自动调用它的 doPost 或 doGet 方法。 Servlet 的主要功能 ▶ 接收用户 HTTP 请求。 ▶ 取得 HTTP 请求提交的数据。 ▶ 调用 JavaBean 对象的方法。 ▶ 生成 HTML 类型或非 HTML Servlet 编程 Servlet 生命周期 Servlet 配置 Servlet 部署 Servlet 示例 重写 doGet 方法 父类 HttpServlet 的 doGet 方法是空的,没有实现任何代码,子 类需要重写此方法。 2 public void doGet(HttpServletRequest request, HttpServletResponse response) 3 throws ServletException, IOException { 3 // Rewrite the method. 4 } 当请求方式为 POST 时自动运行,每次请求都运行一次。 doGet 和 doPost 方法都接收 Web 容器自动创建的请求对象和 响应对象,使得 Servlet 能够解析请求数据和发送响应给客户端。 大纲 Web 基础 Servlet 概述 Servlet 编程0 码力 | 50 页 | 725.36 KB | 1 年前3 Java 应用与开发 - Servlet 编程内,由 Web 容器负责它的对象的创建和销毁,不能直接由 其它类对象来调用。 ▶ 当 Web 容器接收到对它的 HTTP 请求时,自动创建 Servlet 对象,并自动调用它的 doPost 或 doGet 方法。 Servlet 的主要功能 ▶ 接收用户 HTTP 请求。 ▶ 取得 HTTP 请求提交的数据。 ▶ 调用 JavaBean 对象的方法。 ▶ 生成 HTML 类型或非 HTML Servlet 编程 Servlet 生命周期 Servlet 配置 Servlet 部署 Servlet 示例 重写 doGet 方法 父类 HttpServlet 的 doGet 方法是空的,没有实现任何代码,子 类需要重写此方法。 2 public void doGet(HttpServletRequest request, HttpServletResponse response) 3 throws ServletException, IOException { 3 // Rewrite the method. 4 } 当请求方式为 POST 时自动运行,每次请求都运行一次。 doGet 和 doPost 方法都接收 Web 容器自动创建的请求对象和 响应对象,使得 Servlet 能够解析请求数据和发送响应给客户端。 大纲 Web 基础 Servlet 概述 Servlet 编程0 码力 | 50 页 | 725.36 KB | 1 年前3
 《Java 应用与开发》课程讲义 - 王晓东213 16.3.2 类定义 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 16.3.3 重写 doGet 方法 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 16.3.4 重写 doPost 方法 . . . . . . Web 容器负责它 的对象的创建和销毁,不能直接由其它类对象来调用。 • 当 Web 容器接收到对它的 HTTP 请求时,自动创建 Servlet 对象,并自动调用它 的 doPost 或 doGet 方法。 Servlet 的主要功能 • 接收用户 HTTP 请求。 • 取得 HTTP 请求提交的数据。 • 调用 JavaBean 对象的方法。 • 生成 HTML 类型或非 HTML LoginAction extends HttpServlet { 2 // Code goes on. 3 } 16.3.3 重写 doGet 方法 父类 HttpServlet 的 doGet 方法是空的,没有实现任何代码,子类需要重写此方法。 2 public void doGet(HttpServletRequest request, HttpServletResponse response) 30 码力 | 330 页 | 6.54 MB | 1 年前3 《Java 应用与开发》课程讲义 - 王晓东213 16.3.2 类定义 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 16.3.3 重写 doGet 方法 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214 16.3.4 重写 doPost 方法 . . . . . . Web 容器负责它 的对象的创建和销毁,不能直接由其它类对象来调用。 • 当 Web 容器接收到对它的 HTTP 请求时,自动创建 Servlet 对象,并自动调用它 的 doPost 或 doGet 方法。 Servlet 的主要功能 • 接收用户 HTTP 请求。 • 取得 HTTP 请求提交的数据。 • 调用 JavaBean 对象的方法。 • 生成 HTML 类型或非 HTML LoginAction extends HttpServlet { 2 // Code goes on. 3 } 16.3.3 重写 doGet 方法 父类 HttpServlet 的 doGet 方法是空的,没有实现任何代码,子类需要重写此方法。 2 public void doGet(HttpServletRequest request, HttpServletResponse response) 30 码力 | 330 页 | 6.54 MB | 1 年前3
 跟我学Shiro - 张开涛urlPatterns = "/login") public class LoginServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 跟我学 Shiro——http://jinnianshilongnian.iteye.com/ 68 1、doGet 请求时展示登录页面; 2、doPost 时进行登录,登录时收集 username/password 参数,然后提交给 Subject 进行登录。 如果有错误再返回到登录页面;否则跳转到登录成功页面(此处应该返回到访问登录页面 "/formfilterlogin") public class FormFilterLoginServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {0 码力 | 219 页 | 4.16 MB | 10 月前3 跟我学Shiro - 张开涛urlPatterns = "/login") public class LoginServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { 跟我学 Shiro——http://jinnianshilongnian.iteye.com/ 68 1、doGet 请求时展示登录页面; 2、doPost 时进行登录,登录时收集 username/password 参数,然后提交给 Subject 进行登录。 如果有错误再返回到登录页面;否则跳转到登录成功页面(此处应该返回到访问登录页面 "/formfilterlogin") public class FormFilterLoginServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {0 码力 | 219 页 | 4.16 MB | 10 月前3
 Java 应用与开发 - JSP (Java Server Page)服务器接收到请求,如果没有此地址,发出错误响应给 浏览器; 3. Web 服务器检查 JSP 文件和对应的 Servlet 版本的时间是 否一致,如果一致则执行 servlet 的处理请求方法,类似于 doGet 或 doPost,发送响应给浏览器; 4. 版本时间不一致,Web 服务器调用转换系统,将 JSP 的文 本代码转换为 Servlet 的 Java 代码; 5. 将 Java 代码编译为 class 3 % > ▶ 可以同时嵌入多个脚本代码段,但它们都表示在一个方法 内,属于一个代码段,一个脚本内定义的变量,另一个脚本 也可以使用。 ▶ 在代码脚本中定义的变量类似于 Servlet 的 doGet 方法中的 局部变量,未初始化使用是非法的。 例如,连接数据库的代码脚本片段如下: 1 <% 2 Connection cn = null; 3 try { 4 Class.forName("sun0 码力 | 47 页 | 740.36 KB | 1 年前3 Java 应用与开发 - JSP (Java Server Page)服务器接收到请求,如果没有此地址,发出错误响应给 浏览器; 3. Web 服务器检查 JSP 文件和对应的 Servlet 版本的时间是 否一致,如果一致则执行 servlet 的处理请求方法,类似于 doGet 或 doPost,发送响应给浏览器; 4. 版本时间不一致,Web 服务器调用转换系统,将 JSP 的文 本代码转换为 Servlet 的 Java 代码; 5. 将 Java 代码编译为 class 3 % > ▶ 可以同时嵌入多个脚本代码段,但它们都表示在一个方法 内,属于一个代码段,一个脚本内定义的变量,另一个脚本 也可以使用。 ▶ 在代码脚本中定义的变量类似于 Servlet 的 doGet 方法中的 局部变量,未初始化使用是非法的。 例如,连接数据库的代码脚本片段如下: 1 <% 2 Connection cn = null; 3 try { 4 Class.forName("sun0 码力 | 47 页 | 740.36 KB | 1 年前3
 Reference guide for FCL units. Document version 3.2.2TEZcgi.DoPost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540 15.5.11 TEZcgi.DoGet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540 15.5.12 TEZcgi.Values . . component. To use the unit, a descendent of the TEZCGI class should be created and the DoPost (540) or DoGet (540) methods should be overridden. 15.3 Constants, types and variables 15.3.1 Constants hexTable (540) or DoGet (540) methods. To run the program, an instance of this class must be created, and it’s Run (539) method should be invoked. This will analyze the environment and call the DoPost or DoGet method0 码力 | 953 页 | 2.21 MB | 1 年前3 Reference guide for FCL units. Document version 3.2.2TEZcgi.DoPost . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540 15.5.11 TEZcgi.DoGet . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 540 15.5.12 TEZcgi.Values . . component. To use the unit, a descendent of the TEZCGI class should be created and the DoPost (540) or DoGet (540) methods should be overridden. 15.3 Constants, types and variables 15.3.1 Constants hexTable (540) or DoGet (540) methods. To run the program, an instance of this class must be created, and it’s Run (539) method should be invoked. This will analyze the environment and call the DoPost or DoGet method0 码力 | 953 页 | 2.21 MB | 1 年前3
 servlet mechanismservice() doGet() doPost() Get Request Post Request Response Response Web Server HttpServlet subclass 注意: 方法由 HttpServlet 的子类实现0 码力 | 1 页 | 16.55 KB | 1 年前3 servlet mechanismservice() doGet() doPost() Get Request Post Request Response Response Web Server HttpServlet subclass 注意: 方法由 HttpServlet 的子类实现0 码力 | 1 页 | 16.55 KB | 1 年前3
 Java EE 企业应用系统设计 - HTTP 请求处理编程O 请求对象生命周期 在 Java Web 组件开发中,不需要 Servlet 或 JSP 自己创建请求 对象,它们由Web 容器自动创建,并传递给 Servlet 和 JSP 的 服务方法 doGet 和 doPost,在服务处理方法中直接使用请求对 象即可。 大纲 HTTP 请求内容 Java EE 请求对象 请求对象类型与生命周期 O 请求对象创建 每次 Web 服务器接收到 HTTP0 码力 | 27 页 | 565.27 KB | 1 年前3 Java EE 企业应用系统设计 - HTTP 请求处理编程O 请求对象生命周期 在 Java Web 组件开发中,不需要 Servlet 或 JSP 自己创建请求 对象,它们由Web 容器自动创建,并传递给 Servlet 和 JSP 的 服务方法 doGet 和 doPost,在服务处理方法中直接使用请求对 象即可。 大纲 HTTP 请求内容 Java EE 请求对象 请求对象类型与生命周期 O 请求对象创建 每次 Web 服务器接收到 HTTP0 码力 | 27 页 | 565.27 KB | 1 年前3
 Java EE 企业应用系统开发 - HTTP 响应处理编程HTTP 响应的内容 HTTP 响应对象 响应对象功能和方法 响应对象生命周期 1. Web 容器自动为每次 Web 组件的请求生成一个响应对象。 2. Web 容器创建响应对象后,传入到 doGet 或 doPost 方法。 3. 通过响应对象向浏览器发响应。 4. 响应结束后,Web 容器销毁响应对象,释放所占用的内存。 大纲 HTTP 响应的内容 HTTP 响应对象 响应对象功能和方法0 码力 | 26 页 | 575.28 KB | 1 年前3 Java EE 企业应用系统开发 - HTTP 响应处理编程HTTP 响应的内容 HTTP 响应对象 响应对象功能和方法 响应对象生命周期 1. Web 容器自动为每次 Web 组件的请求生成一个响应对象。 2. Web 容器创建响应对象后,传入到 doGet 或 doPost 方法。 3. 通过响应对象向浏览器发响应。 4. 响应结束后,Web 容器销毁响应对象,释放所占用的内存。 大纲 HTTP 响应的内容 HTTP 响应对象 响应对象功能和方法0 码力 | 26 页 | 575.28 KB | 1 年前3
 Java 应用系统开发 - ServletContext 和 Web 配置init(config); 5 this.config = config; 6 } 1. 要取得 ServletConfig 对象需要重写 init 方法,并传递 ServletConfig 参数。然后在 doGet 和 doPost 方法中即可以 使用 config 对象。 2. 与 ServletContext 和 HttpSession 对象不同,Web 容器为 每个 Servlet 实例创建一个 ServletConfig0 码力 | 33 页 | 668.91 KB | 1 年前3 Java 应用系统开发 - ServletContext 和 Web 配置init(config); 5 this.config = config; 6 } 1. 要取得 ServletConfig 对象需要重写 init 方法,并传递 ServletConfig 参数。然后在 doGet 和 doPost 方法中即可以 使用 config 对象。 2. 与 ServletContext 和 HttpSession 对象不同,Web 容器为 每个 Servlet 实例创建一个 ServletConfig0 码力 | 33 页 | 668.91 KB | 1 年前3
 Java 应用与开发 - HTTP 会话跟踪技术会话对象的应用示例 O 会话对象销毁(编程一般在注销功能中) 1 public class LogoutAction extends HttpServlet { 2 public void doGet(HttpServletRequest request, HttpServletResponse response) { 3 HttpSession session = request.getSession();0 码力 | 54 页 | 824.47 KB | 1 年前3 Java 应用与开发 - HTTP 会话跟踪技术会话对象的应用示例 O 会话对象销毁(编程一般在注销功能中) 1 public class LogoutAction extends HttpServlet { 2 public void doGet(HttpServletRequest request, HttpServletResponse response) { 3 HttpSession session = request.getSession();0 码力 | 54 页 | 824.47 KB | 1 年前3
共 11 条
- 1
- 2













