request,setCharacterEncoding("编码");
静态包含
<jsp:Linclude page="路径"><jsp:include>
request,setCharacterEncoding("编码");
静态包含
<jsp:Linclude page="路径"><jsp:include>
内置对象page相当于this。就是当前页面的对象
page作用域只在当前页面有效
page==this--->true
pageContext内置对象能够获取其他的内置对象
比如request,session,,,,
也可以在里面放入键值对,也是使用setAttrubute
也可以获取到属性
可以将键值数据放入到指定的域中
pageContext,SESSION_SCOPE放入到session域中
引入包,直接放入到WEB-INF就可以了,不需要再操作,默认的首页也是可以再web.xml中的<welcome=file-配置qi'shi'ye
init()方法,构造方法只加载一次
不论调用的是get还是post首先会调用Service,前提是要重写Service方法!
监听器能监听相应的值deng
用构造方法防止外部类实例化工具类
如果是web项目可以将jar包放在WEB-INF的lib文件夹下,web项目将会自动识别
a'a'a'a
序列化、持久化:将Goods对象转化为JSON对象
Goods goods=new Goods("香蕉","夏威夷香蕉",100,400);
String json=JSON.toJSONString(goods);
System.out.println(json);
反序列化:将JSON对象转化为Goods对象
String s="{\"des\":\"夏威夷香蕉\",\"inventory\":400,\"name\":\"香蕉\",\"price\":100}";
Goods goods=JSON.parseObject(s,Goods.class);
System.out.println(goods.getName()+" "+goods.getDes()+" "+goods.getInventory()
+" "+goods.getPrice());
对于 index.jsp 的修改 ---之前是加入没有用户登录就是现实 登录 注册两个链接 。 否则就是现实目前登录的用户
<c:choose>
<c:when test="${empty user }">
<a href="<%=request.getContextPath()%>/login.jsp">登录</a>
<a href="<%=request.getContextPath() %>/register.jsp">注册</a>
</c:when>
<c:otherwise>
当前登录用户为:${user.userName}
</c:otherwise>
</c:choose>
对于goods_list.jsp的修改---之前是将tr td 嵌入if-else java语句块中 现在是
<c:choose>
<c:when test="${empty user }">
<a href="<%=request.getContextPath()%>/login.jsp">登录</a>
<a href="<%=request.getContextPath() %>/register.jsp">注册</a>
</c:when>
<c:otherwise>
当前登录用户为:${user.userName}
</c:otherwise>
</c:choose>
适应jstl表达式中的 if if-else 循环标签
<c:set var="age" value="2" scope="request"></c:set>
<c:if test="${age>18}">
<font color="green">你已经成年</font>
</c:if>
if-else
<c:set var="age" value="2" scope="request"></c:set>
<c:choose>
<c:when test="${age>18}">
<font color="green">你已经成年</font>
</c:when>
<c:otherwise>
<font color="red">
你还未成年
</font>
</c:otherwise>
</c:choose>
普通的循环
<c:forEach var="i" begin="1" end="10">
中国${i}<br>
</c:forEach>
遍历集合对象
<%
List<User> list=new ArrayList<>();
list.add(new User("中国1","123",70,"女",false));
list.add(new User("中国2","123",70,"女",false));
list.add(new User("中国3","123",70,"女",false));
list.add(new User("中国4","123",70,"女",false));
list.add(new User("中国5","123",70,"女",false));
request.setAttribute("list",list);
%>
<c:forEach items="${requestScope.list}" var="u">
${u.userName}<br>
</c:forEach>
我们先将list对象放进request 中
然后使用forEach遍历
注意这里的items 必须是用el 表达式取到的
使用 jstl表达式 存值
<c:set var="userName" value="sasas" scope="request"></c:set>
${userName}
第一行,我们把一个变量名为 userName 值为 sasas 的元素放进request 域中 然后使用el表达式的方式取值
取值
<c:out value="${userName}"></c:out>
移除
<c:remove var="userName"/>
放到取值表达式前面我们就不能渠道userName 这个元素了
jstl 使用
1 在网上下载jstl 1.1.2 桌面资料里面有
2 在lib中引入 jstl
3 <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
在我们的jsp 页面上加入以上代码即可使用
使用el表达式获取项目名
${pageContext.request.contextPath}
web jsp、servlet
conroller、view .jsp
service(服务层) 业务逻辑层
dao层:数据库操作 增删改查 mysqlDB
mvc
model viewcontroller
客户端路径:我们查看网页源码时,他已经被解析了,例如网页的头文件尾文件
客户端绝对路径:http://localhost:8080/
服务器路径:服务器端查看源码可以看见,
服务器端绝对路径:http://localhost:8080/web04/
这里的web04/使用request.getContextPath()代替
相对路径:css/style.css css与path.jsp 同级可以直接用
绝度路径:/web04/css/style.css 绝对路径最前面必须是 /然后加上自己的项目名
request.getContextPath() 获取自己的项目名
单例模式:public class JDBCUtil {
//设置一个静态实例
public static JDBCUtil instance=new JDBCUtil();
//私有化构造方法
private JDBCUtil() {
}
public void getConnection() {
System.out.println("得到一个数据库连接");
}
public static void main(String[] args) {
JDBCUtil.instance.getConnection();
}
}
客户端路径:我们查看网页源码时,他已经被解析了,例如网页的头文件尾文件
客户端绝对路径:http://localhost:8080/
服务器路径:服务器端查看源码可以看见,
服务器端绝对路径:http://localhost:8080/web04/
这里的web04/使用request.getContextPath()代替
相对路径:css/style.css css与path.jsp 同级可以直接用
绝度路径:/web04/css/style.css 绝对路径最前面必须是 /然后加上自己的项目名
request.getContextPath() 获取自己的项目名
我们引入CSS文件的时候最好使用绝对路径,这样在其他页面跳转到本页面的时候就能够找到
最好使用<link rel="stylesheet" href="<%=request.getContextPath() %>/css/style.css" type="text/css"/>这种方式
客户端路径:
服务器路径:
相对路径:css/style.css css与path.jsp 同级可以直接用
绝度路径:/web04/css/style.css 绝对路径最前面必须是 /然后加上自己的项目名
request.getContextPath() 获取自己的项目名