Java Web学习笔记
第一章 概述
客户端程序
胖客户端程序RCP
例如:腾讯QQ,迅雷,Excel
缺点:使用前必须安装,占用硬盘资源
瘦客户端程序TCP
例如:门户网站,CRM系统,网上银行
有点:免客户端
B/S与C/S结构
C/S结构缺点:必须安装和维护客户端软件才能使用
B/S结构:只要浏览器就可以.
HTTP与HTTPS
服务器:
Tomcat
Websphere
WebLogic
package com.hello.ch02.firstweb; 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; public class HelloServlet extends HttpServlet { /** * Constructor of the object. */ public HelloServlet() { super(); } /** * Destruction of the servlet. <br> */ public void destroy() { super.destroy(); // Just puts "destroy" string in log // Put your code here } /** * 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.setCharacterEncoding("UTF-8"); // 设置request,response编码方式 request.setCharacterEncoding("UTF-8"); response.setContentType("text/html"); // 设置文档类型 PrintWriter out = response.getWriter(); // 获取out对象 // 输出到客户端浏览器 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>"); String requestURI = request.getRequestURI(); out.println("<form action='" + requestURI + "' method='post'>"); out.println("请输入您的名字: <input type='text' name='name' />"); out.println("<input type='submit' />"); out.println("</form>"); out.println(""); String name = request.getParameter("name"); //获取浏览器提交的name参数 if(name != null && name.trim().length() > 0){ out.println("您好, <b>" + name + "</b>. 欢迎来到Java Web世界."); } out.println(" </BODY>"); out.println("</HTML>"); out.flush(); out.close(); // 关闭out } /** * 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 { this.doGet(request, response); } /** * Initialization of the servlet. <br> * * @throws ServletException if an error occurs */ public void init() throws ServletException { // Put your code here } }