1.jsp基本知识:
(1)加载中文:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
(2)导包:
<%@ page import="com.javabean.Commodity"%>
(3)导jstl:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
(4)java代码写在<% %>里面。
(5)out.print("<li><a href='DetailServlet?id=" + a.getId() + "'>" + a.getCommodity_name()+ "<a><li>");
输出a.getCommodity_name()到页面,设置为超链接,并把id传到相应servlet。
(6)jsp常用隐式对象(不用定义):request、response、session、application等
(7)通过form表单和a标签都可以提交数据到servlet。
1>通过form表单:设置属性值action=“LoginServlet” method=“post”,提交按钮属性值type="submit"即可。
2>通过a标签:
(8)标准标签库(jstl):
1>.<c:forEach items="${H_users}" var="user"></c:forEach>
2><c:if test="${user.category==2}">
3>
<c:choose>
<c:when test="${order.status==1}">
...
</c:when>
<c:otherwise>
...
</c:otherwise>
</c:choose>
2.servlet基本知识:
(1)session的使用:
HttpSession session = request.getSession();
session.setAttribute("user",user);//设置session
String userStr = (String)session.getAttribute("user")//获取
(2)application的使用:
HttpSession session = request.getSession();
application.setAttribute("online",user);//设置application
String online = (String) application.getAttribute("online");//获取
(3)重定向(可以定位到servlet文件):
1>.response.sendRedirect("manage.jsp");
2>.
String site = new String("UserinfoServlet");//进入到首页
response.setStatus(response.SC_MOVED_TEMPORARILY);
response.setHeader("Location", site);
(4)获取jsp页面表单中的值:
String name = request.getParameter("username");
String password = request.getParameter("pwd");
3.cookie
1.添加cookie:
Cookie yzm = new Cookie("code",s);
yzm.setMaxAge(60);//设置过期时间
response.addCookie(yzm);//添加到cookie
2.读取cookie:
Cookie[] cookies = request.getCookies();
for(Cookie cookie : cookies){字
String cookieName = cookie.getName();//获取cookie的名
if(name.equals(cookieName))//判断是不是自己要读取的那个cookie名
{
code2 = cookie.getValue();//如果找到,就取出cookie中的值
}
}
4.sql
1.两张表嵌套的查询:
select s.user_id, commodity_name, c.price FROM shopping_cart as s inner join commodity_info as c on s.commodity_id = c.id;
2.三张表嵌套的查询:
select * from commodity_info as c where c.id = ( select d.c_id from order_detail as d inner join orders as o on o.id = d.order_id GROUP BY d.c_id);