void是对象类型
DateFormat fmt=new SimpleDateFormat(\try{
this.birth=fmt.parse(birth);//字符串转化成日期 }catch 集合:
java.util.*
以Collection:接口提供 list:有序可重复 ArrayList LinkedLink
Set:无 序不可重复 HashSet
Set的子接口
SortedSet:TreeSet
Comparable Comparator 比较大小 comparaTo()
hashcode()返回int 数组:同种类型的变量
int[] array = new ArrayList[10]; length,[]
类型:基本类型 八种 对象类型
String name=\指针或 分配三次内存
2016.3.7 周一
创建项目 发布项目 运行项目
基准地址:http://localhost:8080/one/hello-world
一、创建servlet的流程
1、创建类:HelloWorldServlet,父类:HttpServlet 在Eclipse中会自动编译,拷贝到classes文件夹下 2、在配置文件(web.xml) 定义为servlet
3、在web.xml中为其指派URL
二、常见错误 1、存盘
2、类,配置文件改变后,需要重启tomcat才能生效 3、程序出错症状:浏览器 控制台 4、类名写错 5、url格式错误
正确格式:
1 \开头 “/”分隔符,可出现多次
2 \开头 *代表通配符一般在后面加上.xx的后缀 3 前缀形式 注意:\至多出现一次,最前或最后 4、 “/*” 匹配所有地址
2016.3.8 周二
单实例多线程模型 一个请求一个线程
servlet不能被定义成员变量 会被更改 init() servlet初始化方法
一个servlet产生一个对象 webcontent 网站的根
<%@ %>指令 <% %>脚本 <%= %>输出
<%! %>声明 <%
String basePath=request.getScheme()+\ basePath+=\%>
<%@include file=\ 动态包含 forward();
重定向 浏览器处理 两次请求 rsponse.setRedirect(\ 请求转发 一次请求 // 获取请求转发器 RequestDispatcher dispather = req.getRequestDispatcher(\ //执行转发 dispather.forward(req, resp); req.setAttribute(name,value); getAttribute(name); removeAtrribute(name); ${数据} el表达式 inline 需多少用多少 block 独占一行 http://localhost:8080/one/hello-world?login=&psaaword=&confirm=&gender=F ?后面是请求参数 特殊符号在URL中会转换 dns域名解析 相对地址:/开头的就是 绝对地址:不完整没有http 8080/ 的地址 没有/ 完整地址:以http开头的 可用的 http://localhost:8080:/服务器的跟地址 http://localhost:8080:/one/ 网站的跟地址 相对地址转换为完整地址 分为两种情况 1没有base标签:根据当前请求转换 2有base标签:前面直接附加上base标签的href属性值 在日常生活中加上base标签 好处相对地址都相对于一个固定的地址 如何写base标签? request: getScheme() :返回http https getServiceName() :返回 getServicePort(): 8080 getContextPath(): 返回网站根路径 /one 3.14 周一 从A forward 到B A中对浏览器的输出将被忽略 请求转发: forward 只发一个;include 所有资源整合到一起发送 获取RequestDispatcher(url) url:相对地址:request。getRequestURL() 返回含有网站名的绝对地址 例如:http://localhost:8080/one/a.do 返回/one/a.do 绝对地址:相对于网站的根 request.getContextPath(); 完整地址 不行 X servletcontext.getrequestdispather(\必须绝对地址 redirect jsp原理:有一个转换器,把jsp页面转换成.java文件 一个jsp其实就是一个httpservlet jsp文件三种形式 page页面 java源码 class字节码 jsp页面有哪些内容 指令<%@ %> page include 脚本<% %> X 声明<%! %> X 输出表达式<%= %> X action:include 动态包含 usebean setproperty 过时了 EL表达式 important! &{} 静态模板:html 当然也是important 内置对象:request response application out page(this) ServletContext:俗称网站 容器 环境 获取: servlet:getServletContext(); request: getServletContext(); jsp:application 以上三者,代表同一个对象 3.15 周二 request的两个方法:getParameter(\ getParameterValues(); 少用的方法 getParameterName() getParameterMap() Attribute 相对于对象 成员变量:field java bean规范:就是我们写类的规范 1.命名 2.property 属性 创建user表 id 数值类型 自动增长 主键 name 字符串20 login 字符串8 password 字符串32 birthdate 日期 gender 字符1 JDBC:create database one default character set utf8; 数据源初始化一次