JSP/Servlet
1.JSPMdel1
浏览器<------>JSP/Servlet<------>数据库
2.JSPModel2
浏览器<------>控制器<---->J模型(avaBean)<------>数据库
^
|
|
视图
3.Tomcat数据库连接池
在TOMCAT中,数据库连接池负责分配,管理和释放数据库连接,它允许重复使用一个现有的数据库连接,而不是重新建立连接
3.数据库连接池应用
importjava.sql.Connection
importjava.sql.PreparedStatement
importjava.sql.Resultset
javax.naming.Contentctx=newjavax.naming.InitialContentx();
javax.sql.datasourceds=(javax.sql.datasource)ctx.lookup(dataource);
Connectioncon=ds.getConnection()
PreparedStatementpstmt=conns.prepareStatement("select*fromtable")
Resultsetrs=psmt.executeQuery();
4.Sevlet
extendHttpServlet
doGet,doPost
service方法,再决定调用doGetordoPost
init(),destroy()
5.
HttpServletResponse,
setStatus
sendRedirect
sendError
addHeader("field","value)
setHeader("field","value)
setContextType
setCharacterEncoding
HttpServeletRequest
getRequestURI,getPathInfo,getQueryString,getRequestURL
getSession()
getSession(booleancreate)
HttpSession
isNew,isvalidate,getAttribute,setAttribute
5.使用Requestdispatcher包含web资源
getServletContext().getRequestDispatcher("");
6.解决乱码问题
response.setContentType("text/html;Charset=utf-8")
PrintWriterout=response.getWrite()
output.println("newString(s.getBytes("utf-8","iso-8859-1"))
chinesestr=newString(chineseUTF8.getBytes(iso-8859-1"),utf-8);
7.JSP表达式语言(EL)
${表达式}
8.JSP指令
page页面指令包含下列
language,import,session,buffer,autoflush。。。
include指令
9.JSP内置对象
out,request,response,session,page,exception,config,application
PageContext.getException
............getpage
............getRequest
............getResponse
............getSession
............getServletConfig
............getServletContext
10.JSP标签
<jsp:include>
<jsp:forward>
<jsp:param>
<jsp:useBean>
<jsp:setProperty>
<jsp:getProperty>
11JSTL
<C:OUT>
<C:SET>
<C:IF>
<C:CHOOSE>
<C:WHEN>
<C:OTHERWISE>
<C:FOREACH>