JSP的内置对象不需要声明,在需要的时候调用即可。JSP运行时内部会将JSP代码转化为Servlet代码,其中的对象都有各种各样的属性和方法,我们也可以对于这些属性和方法进行追加。 大致分类有以下几种
内置对象Java类主要功能requestjavax.servlet.http.HttpServletRequest客户端对服务器的请求responsejavax.servlethttp.HttpServletResponse服务器对客户端的响应pageContextjavax.servletjsp.PageContext关于当前JSP页的内容sessionjavaxservlethttp.HttpSession客户端第一次请求时会在服务器内生成一个session,当释放链接时,该session会销毁。这一对象就是对session进行处理applicationjavax.servlet.ServletContext对服务器的具体功能进行操作处理outjavax.servlet.jsp.JspWriter服务器到客户端的链路中的输出流处理configjavaxservlet.ServletConfigJSP文件生成时的初期环境处理pagejavalang.Object当前JSP页的类信息处理exceptionjavalang.Throwable错误信息处理内置对象的属性可以通过 s e t A t t r i b u t e ( ) , g e t A t t r i b u t e ( ) setAttribute(),getAttribute() setAttribute(),getAttribute()来追加类内属性或者读取该类内属性。
属性功能getParameterNames()列举当前请求的所有参数名getParameter(name)带有指定字符串名getParameterValues(name)带有指定字符串名,以数字形式携带;如checkbox 和 multiple listgetCookies()所有的coockie值都由java.servlet.http.Cookie以数组形式携带getMethod()当前请求携带以GET/POST等属性值,上传操作和端口访问一般为POST,一般访问为GETgetSession()携带现在的session值getRemoteAddr()携带客户端的IP地址getProtocol()携带当前服务器使用的协议,用字符串形式表达setCharacterEncoding()规定了客户端传输到服务器过程中的编码用于回应request或者将请求传达给其他页。
属性作用setContentType(type)按照type指定MIME typesetHeader(name,value)将value复制给name,并将之作为头部setDateHeader(name, date)将date赋给name并将其作为头部(ms单位)sendError(status,msg)把错误信息返回错误信息sendRedirect(url)跳转到其他页这里的Redirect方法和之前的forward[Action]都具有相同的功能,都有将当前请求传达给其他页的能力,下面来说明一下他们的区别。 [forward] [sendRedirecrt()]
不同点ForwardsendRedirect()返回方式Forward动作将请求链接直接转给B页,然后B页直接代替A也给出响应sendRedirect()是由A告知B的URL,然后客户点再次建立一条新的连接去访问B页面URL表示即便实际返回的是由B页给出的结果,我们能看到的URL是A的URL当A返回B的URL且客户端访问B时,URL会从A变为B参数在A向B传达期间,可以增加追加变量和信息来供B使用追加变量和信息在返回客户端的过程中丢失为了颜值上面的区别,我们来做一个实验。
#mermaid-svg-svg6Hc35L5DevFKE .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-svg6Hc35L5DevFKE .label text{fill:#333}#mermaid-svg-svg6Hc35L5DevFKE .node rect,#mermaid-svg-svg6Hc35L5DevFKE .node circle,#mermaid-svg-svg6Hc35L5DevFKE .node ellipse,#mermaid-svg-svg6Hc35L5DevFKE .node polygon,#mermaid-svg-svg6Hc35L5DevFKE .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-svg6Hc35L5DevFKE .node .label{text-align:center;fill:#333}#mermaid-svg-svg6Hc35L5DevFKE .node.clickable{cursor:pointer}#mermaid-svg-svg6Hc35L5DevFKE .arrowheadPath{fill:#333}#mermaid-svg-svg6Hc35L5DevFKE .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-svg6Hc35L5DevFKE .flowchart-link{stroke:#333;fill:none}#mermaid-svg-svg6Hc35L5DevFKE .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-svg6Hc35L5DevFKE .edgeLabel rect{opacity:0.9}#mermaid-svg-svg6Hc35L5DevFKE .edgeLabel span{color:#333}#mermaid-svg-svg6Hc35L5DevFKE .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-svg6Hc35L5DevFKE .cluster text{fill:#333}#mermaid-svg-svg6Hc35L5DevFKE div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-svg6Hc35L5DevFKE .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-svg6Hc35L5DevFKE text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-svg6Hc35L5DevFKE .actor-line{stroke:grey}#mermaid-svg-svg6Hc35L5DevFKE .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-svg6Hc35L5DevFKE .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-svg6Hc35L5DevFKE #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-svg6Hc35L5DevFKE .sequenceNumber{fill:#fff}#mermaid-svg-svg6Hc35L5DevFKE #sequencenumber{fill:#333}#mermaid-svg-svg6Hc35L5DevFKE #crosshead path{fill:#333;stroke:#333}#mermaid-svg-svg6Hc35L5DevFKE .messageText{fill:#333;stroke:#333}#mermaid-svg-svg6Hc35L5DevFKE .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-svg6Hc35L5DevFKE .labelText,#mermaid-svg-svg6Hc35L5DevFKE .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-svg6Hc35L5DevFKE .loopText,#mermaid-svg-svg6Hc35L5DevFKE .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-svg6Hc35L5DevFKE .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-svg6Hc35L5DevFKE .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-svg6Hc35L5DevFKE .noteText,#mermaid-svg-svg6Hc35L5DevFKE .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-svg6Hc35L5DevFKE .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-svg6Hc35L5DevFKE .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-svg6Hc35L5DevFKE .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-svg6Hc35L5DevFKE .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-svg6Hc35L5DevFKE .section{stroke:none;opacity:0.2}#mermaid-svg-svg6Hc35L5DevFKE .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-svg6Hc35L5DevFKE .section2{fill:#fff400}#mermaid-svg-svg6Hc35L5DevFKE .section1,#mermaid-svg-svg6Hc35L5DevFKE .section3{fill:#fff;opacity:0.2}#mermaid-svg-svg6Hc35L5DevFKE .sectionTitle0{fill:#333}#mermaid-svg-svg6Hc35L5DevFKE .sectionTitle1{fill:#333}#mermaid-svg-svg6Hc35L5DevFKE .sectionTitle2{fill:#333}#mermaid-svg-svg6Hc35L5DevFKE .sectionTitle3{fill:#333}#mermaid-svg-svg6Hc35L5DevFKE .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-svg6Hc35L5DevFKE .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-svg6Hc35L5DevFKE .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-svg6Hc35L5DevFKE .grid path{stroke-width:0}#mermaid-svg-svg6Hc35L5DevFKE .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-svg6Hc35L5DevFKE .task{stroke-width:2}#mermaid-svg-svg6Hc35L5DevFKE .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-svg6Hc35L5DevFKE .taskText:not([font-size]){font-size:11px}#mermaid-svg-svg6Hc35L5DevFKE .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-svg6Hc35L5DevFKE .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-svg6Hc35L5DevFKE .task.clickable{cursor:pointer}#mermaid-svg-svg6Hc35L5DevFKE .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-svg6Hc35L5DevFKE .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-svg6Hc35L5DevFKE .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-svg6Hc35L5DevFKE .taskText0,#mermaid-svg-svg6Hc35L5DevFKE .taskText1,#mermaid-svg-svg6Hc35L5DevFKE .taskText2,#mermaid-svg-svg6Hc35L5DevFKE .taskText3{fill:#fff}#mermaid-svg-svg6Hc35L5DevFKE .task0,#mermaid-svg-svg6Hc35L5DevFKE .task1,#mermaid-svg-svg6Hc35L5DevFKE .task2,#mermaid-svg-svg6Hc35L5DevFKE .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-svg6Hc35L5DevFKE .taskTextOutside0,#mermaid-svg-svg6Hc35L5DevFKE .taskTextOutside2{fill:#000}#mermaid-svg-svg6Hc35L5DevFKE .taskTextOutside1,#mermaid-svg-svg6Hc35L5DevFKE .taskTextOutside3{fill:#000}#mermaid-svg-svg6Hc35L5DevFKE .active0,#mermaid-svg-svg6Hc35L5DevFKE .active1,#mermaid-svg-svg6Hc35L5DevFKE .active2,#mermaid-svg-svg6Hc35L5DevFKE .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-svg6Hc35L5DevFKE .activeText0,#mermaid-svg-svg6Hc35L5DevFKE .activeText1,#mermaid-svg-svg6Hc35L5DevFKE .activeText2,#mermaid-svg-svg6Hc35L5DevFKE .activeText3{fill:#000 !important}#mermaid-svg-svg6Hc35L5DevFKE .done0,#mermaid-svg-svg6Hc35L5DevFKE .done1,#mermaid-svg-svg6Hc35L5DevFKE .done2,#mermaid-svg-svg6Hc35L5DevFKE .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-svg6Hc35L5DevFKE .doneText0,#mermaid-svg-svg6Hc35L5DevFKE .doneText1,#mermaid-svg-svg6Hc35L5DevFKE .doneText2,#mermaid-svg-svg6Hc35L5DevFKE .doneText3{fill:#000 !important}#mermaid-svg-svg6Hc35L5DevFKE .crit0,#mermaid-svg-svg6Hc35L5DevFKE .crit1,#mermaid-svg-svg6Hc35L5DevFKE .crit2,#mermaid-svg-svg6Hc35L5DevFKE .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-svg6Hc35L5DevFKE .activeCrit0,#mermaid-svg-svg6Hc35L5DevFKE .activeCrit1,#mermaid-svg-svg6Hc35L5DevFKE .activeCrit2,#mermaid-svg-svg6Hc35L5DevFKE .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-svg6Hc35L5DevFKE .doneCrit0,#mermaid-svg-svg6Hc35L5DevFKE .doneCrit1,#mermaid-svg-svg6Hc35L5DevFKE .doneCrit2,#mermaid-svg-svg6Hc35L5DevFKE .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-svg6Hc35L5DevFKE .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-svg6Hc35L5DevFKE .milestoneText{font-style:italic}#mermaid-svg-svg6Hc35L5DevFKE .doneCritText0,#mermaid-svg-svg6Hc35L5DevFKE .doneCritText1,#mermaid-svg-svg6Hc35L5DevFKE .doneCritText2,#mermaid-svg-svg6Hc35L5DevFKE .doneCritText3{fill:#000 !important}#mermaid-svg-svg6Hc35L5DevFKE .activeCritText0,#mermaid-svg-svg6Hc35L5DevFKE .activeCritText1,#mermaid-svg-svg6Hc35L5DevFKE .activeCritText2,#mermaid-svg-svg6Hc35L5DevFKE .activeCritText3{fill:#000 !important}#mermaid-svg-svg6Hc35L5DevFKE .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-svg6Hc35L5DevFKE g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-svg6Hc35L5DevFKE g.classGroup text .title{font-weight:bolder}#mermaid-svg-svg6Hc35L5DevFKE g.clickable{cursor:pointer}#mermaid-svg-svg6Hc35L5DevFKE g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-svg6Hc35L5DevFKE g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-svg6Hc35L5DevFKE .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-svg6Hc35L5DevFKE .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-svg6Hc35L5DevFKE .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-svg6Hc35L5DevFKE .dashed-line{stroke-dasharray:3}#mermaid-svg-svg6Hc35L5DevFKE #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-svg6Hc35L5DevFKE #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-svg6Hc35L5DevFKE #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-svg6Hc35L5DevFKE #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-svg6Hc35L5DevFKE #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-svg6Hc35L5DevFKE #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-svg6Hc35L5DevFKE #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-svg6Hc35L5DevFKE #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-svg6Hc35L5DevFKE .commit-id,#mermaid-svg-svg6Hc35L5DevFKE .commit-msg,#mermaid-svg-svg6Hc35L5DevFKE .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-svg6Hc35L5DevFKE .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-svg6Hc35L5DevFKE .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-svg6Hc35L5DevFKE g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-svg6Hc35L5DevFKE g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-svg6Hc35L5DevFKE g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-svg6Hc35L5DevFKE g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-svg6Hc35L5DevFKE g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-svg6Hc35L5DevFKE g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-svg6Hc35L5DevFKE .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-svg6Hc35L5DevFKE .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-svg6Hc35L5DevFKE .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-svg6Hc35L5DevFKE .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-svg6Hc35L5DevFKE .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-svg6Hc35L5DevFKE .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-svg6Hc35L5DevFKE .edgeLabel text{fill:#333}#mermaid-svg-svg6Hc35L5DevFKE .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-svg6Hc35L5DevFKE .node circle.state-start{fill:black;stroke:black}#mermaid-svg-svg6Hc35L5DevFKE .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-svg6Hc35L5DevFKE #statediagram-barbEnd{fill:#9370db}#mermaid-svg-svg6Hc35L5DevFKE .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-svg6Hc35L5DevFKE .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-svg6Hc35L5DevFKE .statediagram-state .divider{stroke:#9370db}#mermaid-svg-svg6Hc35L5DevFKE .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-svg6Hc35L5DevFKE .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-svg6Hc35L5DevFKE .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-svg6Hc35L5DevFKE .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-svg6Hc35L5DevFKE .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-svg6Hc35L5DevFKE .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-svg6Hc35L5DevFKE .note-edge{stroke-dasharray:5}#mermaid-svg-svg6Hc35L5DevFKE .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-svg6Hc35L5DevFKE .error-icon{fill:#522}#mermaid-svg-svg6Hc35L5DevFKE .error-text{fill:#522;stroke:#522}#mermaid-svg-svg6Hc35L5DevFKE .edge-thickness-normal{stroke-width:2px}#mermaid-svg-svg6Hc35L5DevFKE .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-svg6Hc35L5DevFKE .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-svg6Hc35L5DevFKE .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-svg6Hc35L5DevFKE .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-svg6Hc35L5DevFKE .marker{fill:#333}#mermaid-svg-svg6Hc35L5DevFKE .marker.cross{stroke:#333} :root { --mermaid-font-family: "trebuchet ms", verdana, arial;} #mermaid-svg-svg6Hc35L5DevFKE { color: rgba(0, 0, 0, 0.75); font: ; } page_control forward_action2 response_sendRedirect page_control_end实验要求如上所示,我们分别用两种方法来指定同一个终结页面,并在其中追加一个值,看看这个值是否会在传递过程中消失。
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML> <HEAD><TITLE>ch06 : page_control.jsp</TITLE></HEAD> <BODY> <H2>forward, sendRedirect test</H2> <HR> <form method=post action=forward_action2.jsp> forward action : <input type=text name=username> <input type=submit value="确认"> </form> <form method=post action=response_sendRedirect.jsp> response.sendRedirect : <input type=text name=username> <input type=submit value="确认"> </form> </BODY> </HTML>forward_action2.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <% request.setCharacterEncoding("UTF-8"); %> <jsp:forward page="page_control_end.jsp"> <jsp:param name="tel" value="000-000-0000" /> </jsp:forward>不仅保留了原来的输入,还可以追加新的变量输入
sendRedirect()
<% response.sendRedirect("page_control_end.jsp"); %> //<% response.sendRedirect("page_control_end.jsp")?username="Batman"&tel="1234" %> 如果想要中间追加值,需要用这种方式来直接赋值可以看到,传输过程中原本的输入值丢失了。
page_control_end
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head><TITLE>ch06 : page_control_end.jsp</TITLE></HEAD> <BODY> <div align="center"> <H2>forward action & sendRedirect() 结果</H2> <HR> 现在看到的页面是 page_control_end.jsp <HR> 姓名 : <%= request.getParameter("username") %> <BR> 电话号码 : <%= request.getParameter("tel") %> </div> </BODY> </HTML>客户端传输给客户端的输出流数据。
属性作用getBufferSize()管理缓存数据getRemaining()告知目前缓存可用空间比率clearBuffer()清空缓存,,当前信息删除flush()清空缓存和输出流,当前信息发送到客户端close()关闭输出流并清空缓存,当前信息发送到客户端println(content)输出缓存内容,换行。print(content)输出缓存内容 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML> <HEAD><TITLE>ch06 : out.jsp</TITLE></HEAD> <BODY> <div align="center"> <H2> out </H2> <HR> 1. 设定的缓存大小 : <%= out.getBufferSize() %> <BR> 2. 剩余缓存大小比率 : <%= out.getRemaining() %> <BR> <% out.flush(); %> 3. flush 后剩余的BUFF大小 : <%= out.getRemaining() %> <BR> <%--清空输出流,3无法发送到客户端--%> <% out.clearBuffer(); %> <%--clear()与flush()冲突,使用flush后不可以使用clear--%> 4. clear 后剩余的BUFF大小 : <%= out.getRemaining() %> <BR> <%--后面close会把当前内容发送到客户端然后终结buffer,这部分可以看到--%> <% out.close(); %> 5. close 后剩余的BUFF大小 : <%= out.getRemaining() %> <BR> <%--已经关闭了缓存,以后的写入无法在发给输出端,这一段内容无法展示在客户端上--%> </div> </BODY> </HTML>session是服务器上存储来自客户端信息的item。HTTP协议是非连接型协议,因此打印一页后,客户端和服务器的连接断了。 因此,一次登录的用户在注销之前页,移动应该保存信息,为此我们使用了Cookie和Session。 Cookie不存在与第一次访问服务器
属性功能getId()将对应访问的session ID以字符串形态返回getCreatingTime()将session生成后的时间以long形式返回getLastAccessedTime()上一次访问的时间,long返回getMaxInactiveInterval()以秒为单位返回session持续时间的设定值setMaxInactiveInterval(t)设定session持续时间invalidate()终结当前session,与之相关的值也全部清除getAttribute(attr)以字符串型将attr的值转变为java.lang.ObjectsetAttribute(name,attr)将name设定为java.lang.Object attr 的名字 <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML> <HEAD><TITLE>ch06 :session.jsp</TITLE></HEAD> <BODY> <div align="center"> <H2>session test </H2> <HR> <% // isNew() 第一次访问时设定的session值 if(session.isNew()) { out.println("<script> alert('登录验证已过期,请重新登录') </script>"); session.setAttribute("login","布鲁斯韦恩"); } %> # 欢迎 <%= session.getAttribute("login") %>!!!!<BR> 1. Session ID : <%= session.getId() %> <BR> 2. Session duration : <%= session.getMaxInactiveInterval() %> <BR> </div> </BODY> </HTML>只有第一次访问时弹出该窗口。 如果在body内尾部增加如下代码: <%session.invalidate()%>则每次刷新都会弹出该窗口,因为生产的session被立刻删除了。
application是管理整个网页应用程序(context)的对象,可以通过application对象设定并参考各个服务器或JSP想要共享的各种信息。 application是javax.servlet.ServletContext客体作为参照变量,通过config对象生成 ServletContext客体提供与集装箱相关的各种信息,通过application参照变数获取服务器运行环境或服务器资源相关信息或记录登录文件等工作。 application 内置客体一般具有tomcat的起始和结束生活周期。 各类型提供很多方法,主要用于开发具有管理功能的网页应用。
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head><TITLE> </TITLE></HEAD> <BODY> <div align="center"> <H2>ch06 :application test</H2> <HR> 1. Server Info : <%= application.getServerInfo() %> <BR> 2. Servlet API Version Info : <%= application.getMajorVersion() +"."+application.getMinorVersion() %> <BR> 3. application.jsp PATH :<%= application.getRealPath("application.jsp") %> <BR> <HR> feed username "Bruse" to setAttribute <P> <% application.setAttribute("username","Bruse"); application.log("username=Bruse"); application.setAttribute("count",1) ; %> <a href="application_result.jsp">OK</a> </div> </BODY> </HTML> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.io.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML> <HEAD> <TITLE> </TITLE></HEAD> <BODY> <div align="center"> <H2>application result</H2> <HR> username : <%= application.getAttribute("username") %> <P> <% Integer count = (Integer)application.getAttribute("count"); int cnt = count.intValue()+1; application.setAttribute("count",cnt); %> count : <%= cnt %> </div> </BODY> </HTML>config:默认生成的Servlet的初値设定。有getInitParameterNames(),getInitParameter(name)等。
page是JSP容器生成的servlet接口指向自己的指针变量,JSP指向自己时使用。不常用。 exception:JSP页出现错误根据对应的exception选项跳转到对应的错误页 getMessage():返回错误信息 printStackTrace():用标准输出流输出[stack]栈信息 toString():错误信息和意外类名一起返回
通过该对象可以获取其他所有对象的。
属性功能getPage()当前页返回servlet接口页getRequest()当前页返回客户端请求页getResponse()当前页返回客户端响应页getOut()当前页生成返回servlet接口页getSession()当前页生成返回输出流的out页getServletConfig()当前页返回config页(默认设置)getServletContext()当前页生成返回容器应用页getException()返回指定对应错误的错误页可以跳转页面的方法有两种,forward方法和forward动作,一个是java代码一个是标签功能。工程用一般用第一种方法,对于实验用不知道源码的情况下,第二种更便利。
forward method: pageContext.forward(“HelloWorld.jsp”) forward action: <jsp:forward page=“HelloWorld.jsp” />与之相似的还有include
➊ include() method : <% out.flush(); pageContext.include(“HelloWorld.jsp”); %> ➋ include action : <jsp:include page=“HelloWorld.jsp” flush=true />首先来看他们各自的生命周期,Application最长,它当服务启动之后就生成,直到服务彻底结束才会释放。在Application活动期间,服务器会收到复数个访问者的访问,会建立连接保存并生成对应的多个session来储存访问客户端的信息。而每次访问后,用户可能会有不同的需求,客户端也因此会发出不止一次的请求,由于当完成某一个具体的任务,该请求就会终结,因此一个session内含多个request。(打开百度翻译,你翻译一个单词以后,对应的request就结束了,但是你的session持续存在,直到你关闭这个网页,但是其他用户可能还在用这个网页,因此你的session会被释放,而整个服务不会停止) 而一个请求可能由一个页面完成,也可能需要跳转到其他页面完成(百度翻译的人工翻译,就是从翻译页面跳转到另一个页面去处理,这个过程本质就是从一个页跳转到了另一个页,跳转本身也是一个请求) session存储的信息当然可以共享给其下的对应请求与页,session的叶节点往往不止一个。这种结构保障了数据传递和资源共享。 request起始于对应页的请求,当前页返回对应数据后就释放。 session起始于对应容器对某页或文件的请求,当web浏览器结束或规定时间过后被释放。 application起始于应用开始,直到应用终结结束。
在这个过程中,setAttribute(String name, Object value)可以将数据存到对应的属性中,而getAttribute(String name)则可以返回对应的值。
最新的程序架构特征之一是以容器为基础的结构。 从程序的角度来看,容器是指在参与程序执行的同时,能够实施模块化程序,并支持程序间顺利交换数据的软件。 JSP之所以能利用内置对象进行速成管理,是因为JSP和Bean对象被Tomcat的容器管理并实行。 网页程序是以容器为基础的,代表性的框架软件spring也是以容器为基础的程序模式。 这些容器基础项目的长处如下
程序模块化容易独立运行模块之间的数据交换容易在个别程序转换画面/状态时,容易维持/管理数据在JSP,通过容器管理的内置客体,可以根据各自生命周期的起点共享任意对象MVC MVC模式是指将程序分为Model、View、Controller三个角色,体现软件设计模式。 根据MVC模式,JSP只能履行View的作用。 即,只提供在画面中打印数据的功能,问题在于如何将控制器处理的数据(例如从数据库中带回)传达给JSP。 如若使用MVC模式,JSP无需另行带回数据即可输出数据,这时使用JSP内置对象的属性管理。 举例说,控制器处理的数据利用request.setAttribute( )储存后,用显示在画面的JSP进行封装,在相关JSP中通过request内置对象可以引用数据,因此可以实现完整的MVC模式。 有效构成 view的方法是jsp:useBean, jsp:getProperty, 使用表现式或表现语言(Expression Language)和JSTL时更方便地实现view。
#mermaid-svg-mt5xIkb7tqZEjh5y .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-mt5xIkb7tqZEjh5y .label text{fill:#333}#mermaid-svg-mt5xIkb7tqZEjh5y .node rect,#mermaid-svg-mt5xIkb7tqZEjh5y .node circle,#mermaid-svg-mt5xIkb7tqZEjh5y .node ellipse,#mermaid-svg-mt5xIkb7tqZEjh5y .node polygon,#mermaid-svg-mt5xIkb7tqZEjh5y .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-mt5xIkb7tqZEjh5y .node .label{text-align:center;fill:#333}#mermaid-svg-mt5xIkb7tqZEjh5y .node.clickable{cursor:pointer}#mermaid-svg-mt5xIkb7tqZEjh5y .arrowheadPath{fill:#333}#mermaid-svg-mt5xIkb7tqZEjh5y .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-mt5xIkb7tqZEjh5y .flowchart-link{stroke:#333;fill:none}#mermaid-svg-mt5xIkb7tqZEjh5y .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-mt5xIkb7tqZEjh5y .edgeLabel rect{opacity:0.9}#mermaid-svg-mt5xIkb7tqZEjh5y .edgeLabel span{color:#333}#mermaid-svg-mt5xIkb7tqZEjh5y .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-mt5xIkb7tqZEjh5y .cluster text{fill:#333}#mermaid-svg-mt5xIkb7tqZEjh5y div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-mt5xIkb7tqZEjh5y .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-mt5xIkb7tqZEjh5y text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-mt5xIkb7tqZEjh5y .actor-line{stroke:grey}#mermaid-svg-mt5xIkb7tqZEjh5y .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-mt5xIkb7tqZEjh5y .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-mt5xIkb7tqZEjh5y #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-mt5xIkb7tqZEjh5y .sequenceNumber{fill:#fff}#mermaid-svg-mt5xIkb7tqZEjh5y #sequencenumber{fill:#333}#mermaid-svg-mt5xIkb7tqZEjh5y #crosshead path{fill:#333;stroke:#333}#mermaid-svg-mt5xIkb7tqZEjh5y .messageText{fill:#333;stroke:#333}#mermaid-svg-mt5xIkb7tqZEjh5y .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-mt5xIkb7tqZEjh5y .labelText,#mermaid-svg-mt5xIkb7tqZEjh5y .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-mt5xIkb7tqZEjh5y .loopText,#mermaid-svg-mt5xIkb7tqZEjh5y .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-mt5xIkb7tqZEjh5y .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-mt5xIkb7tqZEjh5y .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-mt5xIkb7tqZEjh5y .noteText,#mermaid-svg-mt5xIkb7tqZEjh5y .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-mt5xIkb7tqZEjh5y .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-mt5xIkb7tqZEjh5y .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-mt5xIkb7tqZEjh5y .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-mt5xIkb7tqZEjh5y .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-mt5xIkb7tqZEjh5y .section{stroke:none;opacity:0.2}#mermaid-svg-mt5xIkb7tqZEjh5y .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-mt5xIkb7tqZEjh5y .section2{fill:#fff400}#mermaid-svg-mt5xIkb7tqZEjh5y .section1,#mermaid-svg-mt5xIkb7tqZEjh5y .section3{fill:#fff;opacity:0.2}#mermaid-svg-mt5xIkb7tqZEjh5y .sectionTitle0{fill:#333}#mermaid-svg-mt5xIkb7tqZEjh5y .sectionTitle1{fill:#333}#mermaid-svg-mt5xIkb7tqZEjh5y .sectionTitle2{fill:#333}#mermaid-svg-mt5xIkb7tqZEjh5y .sectionTitle3{fill:#333}#mermaid-svg-mt5xIkb7tqZEjh5y .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-mt5xIkb7tqZEjh5y .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-mt5xIkb7tqZEjh5y .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-mt5xIkb7tqZEjh5y .grid path{stroke-width:0}#mermaid-svg-mt5xIkb7tqZEjh5y .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-mt5xIkb7tqZEjh5y .task{stroke-width:2}#mermaid-svg-mt5xIkb7tqZEjh5y .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-mt5xIkb7tqZEjh5y .taskText:not([font-size]){font-size:11px}#mermaid-svg-mt5xIkb7tqZEjh5y .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-mt5xIkb7tqZEjh5y .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-mt5xIkb7tqZEjh5y .task.clickable{cursor:pointer}#mermaid-svg-mt5xIkb7tqZEjh5y .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-mt5xIkb7tqZEjh5y .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-mt5xIkb7tqZEjh5y .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-mt5xIkb7tqZEjh5y .taskText0,#mermaid-svg-mt5xIkb7tqZEjh5y .taskText1,#mermaid-svg-mt5xIkb7tqZEjh5y .taskText2,#mermaid-svg-mt5xIkb7tqZEjh5y .taskText3{fill:#fff}#mermaid-svg-mt5xIkb7tqZEjh5y .task0,#mermaid-svg-mt5xIkb7tqZEjh5y .task1,#mermaid-svg-mt5xIkb7tqZEjh5y .task2,#mermaid-svg-mt5xIkb7tqZEjh5y .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-mt5xIkb7tqZEjh5y .taskTextOutside0,#mermaid-svg-mt5xIkb7tqZEjh5y .taskTextOutside2{fill:#000}#mermaid-svg-mt5xIkb7tqZEjh5y .taskTextOutside1,#mermaid-svg-mt5xIkb7tqZEjh5y .taskTextOutside3{fill:#000}#mermaid-svg-mt5xIkb7tqZEjh5y .active0,#mermaid-svg-mt5xIkb7tqZEjh5y .active1,#mermaid-svg-mt5xIkb7tqZEjh5y .active2,#mermaid-svg-mt5xIkb7tqZEjh5y .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-mt5xIkb7tqZEjh5y .activeText0,#mermaid-svg-mt5xIkb7tqZEjh5y .activeText1,#mermaid-svg-mt5xIkb7tqZEjh5y .activeText2,#mermaid-svg-mt5xIkb7tqZEjh5y .activeText3{fill:#000 !important}#mermaid-svg-mt5xIkb7tqZEjh5y .done0,#mermaid-svg-mt5xIkb7tqZEjh5y .done1,#mermaid-svg-mt5xIkb7tqZEjh5y .done2,#mermaid-svg-mt5xIkb7tqZEjh5y .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-mt5xIkb7tqZEjh5y .doneText0,#mermaid-svg-mt5xIkb7tqZEjh5y .doneText1,#mermaid-svg-mt5xIkb7tqZEjh5y .doneText2,#mermaid-svg-mt5xIkb7tqZEjh5y .doneText3{fill:#000 !important}#mermaid-svg-mt5xIkb7tqZEjh5y .crit0,#mermaid-svg-mt5xIkb7tqZEjh5y .crit1,#mermaid-svg-mt5xIkb7tqZEjh5y .crit2,#mermaid-svg-mt5xIkb7tqZEjh5y .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-mt5xIkb7tqZEjh5y .activeCrit0,#mermaid-svg-mt5xIkb7tqZEjh5y .activeCrit1,#mermaid-svg-mt5xIkb7tqZEjh5y .activeCrit2,#mermaid-svg-mt5xIkb7tqZEjh5y .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-mt5xIkb7tqZEjh5y .doneCrit0,#mermaid-svg-mt5xIkb7tqZEjh5y .doneCrit1,#mermaid-svg-mt5xIkb7tqZEjh5y .doneCrit2,#mermaid-svg-mt5xIkb7tqZEjh5y .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-mt5xIkb7tqZEjh5y .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-mt5xIkb7tqZEjh5y .milestoneText{font-style:italic}#mermaid-svg-mt5xIkb7tqZEjh5y .doneCritText0,#mermaid-svg-mt5xIkb7tqZEjh5y .doneCritText1,#mermaid-svg-mt5xIkb7tqZEjh5y .doneCritText2,#mermaid-svg-mt5xIkb7tqZEjh5y .doneCritText3{fill:#000 !important}#mermaid-svg-mt5xIkb7tqZEjh5y .activeCritText0,#mermaid-svg-mt5xIkb7tqZEjh5y .activeCritText1,#mermaid-svg-mt5xIkb7tqZEjh5y .activeCritText2,#mermaid-svg-mt5xIkb7tqZEjh5y .activeCritText3{fill:#000 !important}#mermaid-svg-mt5xIkb7tqZEjh5y .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-mt5xIkb7tqZEjh5y g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-mt5xIkb7tqZEjh5y g.classGroup text .title{font-weight:bolder}#mermaid-svg-mt5xIkb7tqZEjh5y g.clickable{cursor:pointer}#mermaid-svg-mt5xIkb7tqZEjh5y g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-mt5xIkb7tqZEjh5y g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-mt5xIkb7tqZEjh5y .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-mt5xIkb7tqZEjh5y .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-mt5xIkb7tqZEjh5y .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-mt5xIkb7tqZEjh5y .dashed-line{stroke-dasharray:3}#mermaid-svg-mt5xIkb7tqZEjh5y #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-mt5xIkb7tqZEjh5y #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-mt5xIkb7tqZEjh5y #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-mt5xIkb7tqZEjh5y #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-mt5xIkb7tqZEjh5y #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-mt5xIkb7tqZEjh5y #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-mt5xIkb7tqZEjh5y #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-mt5xIkb7tqZEjh5y #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-mt5xIkb7tqZEjh5y .commit-id,#mermaid-svg-mt5xIkb7tqZEjh5y .commit-msg,#mermaid-svg-mt5xIkb7tqZEjh5y .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-mt5xIkb7tqZEjh5y .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-mt5xIkb7tqZEjh5y .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-mt5xIkb7tqZEjh5y g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-mt5xIkb7tqZEjh5y g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-mt5xIkb7tqZEjh5y g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-mt5xIkb7tqZEjh5y g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-mt5xIkb7tqZEjh5y g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-mt5xIkb7tqZEjh5y g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-mt5xIkb7tqZEjh5y .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-mt5xIkb7tqZEjh5y .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-mt5xIkb7tqZEjh5y .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-mt5xIkb7tqZEjh5y .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-mt5xIkb7tqZEjh5y .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-mt5xIkb7tqZEjh5y .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-mt5xIkb7tqZEjh5y .edgeLabel text{fill:#333}#mermaid-svg-mt5xIkb7tqZEjh5y .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-mt5xIkb7tqZEjh5y .node circle.state-start{fill:black;stroke:black}#mermaid-svg-mt5xIkb7tqZEjh5y .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-mt5xIkb7tqZEjh5y #statediagram-barbEnd{fill:#9370db}#mermaid-svg-mt5xIkb7tqZEjh5y .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-mt5xIkb7tqZEjh5y .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-mt5xIkb7tqZEjh5y .statediagram-state .divider{stroke:#9370db}#mermaid-svg-mt5xIkb7tqZEjh5y .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-mt5xIkb7tqZEjh5y .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-mt5xIkb7tqZEjh5y .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-mt5xIkb7tqZEjh5y .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-mt5xIkb7tqZEjh5y .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-mt5xIkb7tqZEjh5y .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-mt5xIkb7tqZEjh5y .note-edge{stroke-dasharray:5}#mermaid-svg-mt5xIkb7tqZEjh5y .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-mt5xIkb7tqZEjh5y .error-icon{fill:#522}#mermaid-svg-mt5xIkb7tqZEjh5y .error-text{fill:#522;stroke:#522}#mermaid-svg-mt5xIkb7tqZEjh5y .edge-thickness-normal{stroke-width:2px}#mermaid-svg-mt5xIkb7tqZEjh5y .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-mt5xIkb7tqZEjh5y .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-mt5xIkb7tqZEjh5y .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-mt5xIkb7tqZEjh5y .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-mt5xIkb7tqZEjh5y .marker{fill:#333}#mermaid-svg-mt5xIkb7tqZEjh5y .marker.cross{stroke:#333} :root { --mermaid-font-family: "trebuchet ms", verdana, arial;} #mermaid-svg-mt5xIkb7tqZEjh5y { color: rgba(0, 0, 0, 0.75); font: ; } login selProduct add CheckOutlogin
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>ch06 : login.jsp</title> </head> <body> <div align="center"> <H2>Log in</H2> <form name="form1" method="POST" action="selProduct.jsp"> <input type="text" name="username"/> <input type="submit" value="Login"/> </form> </div> </body> </html>selProduct
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML> <HEAD> <title>ch06 : selProduct.jsp</title> </head> <% request.setCharacterEncoding("UTF-8"); // euc-kr session.setAttribute("username",request.getParameter("username")); %> <body> <div align="center"> <H2>Choose Item</H2> <HR> Welcome!!! Mr/Miss <%=session.getAttribute("username") %>! <HR> <form name="form1" method="POST" action="add.jsp"> <SELECT name="product"> <option>Apple</option> <option>Orange</option> <option>Banana</option> <option>Lemon</option> <option>Melon</option> </SELECT> <input type="submit" value="Add"/> </form> <a href="checkOut.jsp">Check</a> </div> </body> </html>add
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML> <HEAD> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>ch05 : add.jsp</title> </HEAD> <body> <% request.setCharacterEncoding("UTF-8"); String productname = request.getParameter("product"); ArrayList<String> list = (ArrayList)session.getAttribute("productlist"); if(list == null) { list = new ArrayList<String>(); session.setAttribute("productlist",list); } list.add(productname); %> <script> alert("<%=productname %> added successfully !!"); history.go(-1); </script> </body> </html>CheckOut
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <HTML> <HEAD> <meta http-equiv="Content-Type" content="text/html; charset=EUC-KR"> <title>ch06 : checkOut.jsp</title> </HEAD> <body> <div align="center"> <H2>Result</H2> The Item Which have been choosed <HR> <% ArrayList list = (ArrayList)session.getAttribute("productlist"); if(list == null) { out.println("NO ITEM HERE!!!"); } else { for(Object productname:list) { out.println(productname+"<BR>"); } } %> </div> </body> </html>通过上面的串联实验,我们可以发现,Login的对象不论是谁,他们的操作结果都会在最终页面可见,也就证明了数据的共享过程。
Ex2)共享数据操作例2:
#mermaid-svg-PAgcNzrAYYcsdQiU .label{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);fill:#333;color:#333}#mermaid-svg-PAgcNzrAYYcsdQiU .label text{fill:#333}#mermaid-svg-PAgcNzrAYYcsdQiU .node rect,#mermaid-svg-PAgcNzrAYYcsdQiU .node circle,#mermaid-svg-PAgcNzrAYYcsdQiU .node ellipse,#mermaid-svg-PAgcNzrAYYcsdQiU .node polygon,#mermaid-svg-PAgcNzrAYYcsdQiU .node path{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-PAgcNzrAYYcsdQiU .node .label{text-align:center;fill:#333}#mermaid-svg-PAgcNzrAYYcsdQiU .node.clickable{cursor:pointer}#mermaid-svg-PAgcNzrAYYcsdQiU .arrowheadPath{fill:#333}#mermaid-svg-PAgcNzrAYYcsdQiU .edgePath .path{stroke:#333;stroke-width:1.5px}#mermaid-svg-PAgcNzrAYYcsdQiU .flowchart-link{stroke:#333;fill:none}#mermaid-svg-PAgcNzrAYYcsdQiU .edgeLabel{background-color:#e8e8e8;text-align:center}#mermaid-svg-PAgcNzrAYYcsdQiU .edgeLabel rect{opacity:0.9}#mermaid-svg-PAgcNzrAYYcsdQiU .edgeLabel span{color:#333}#mermaid-svg-PAgcNzrAYYcsdQiU .cluster rect{fill:#ffffde;stroke:#aa3;stroke-width:1px}#mermaid-svg-PAgcNzrAYYcsdQiU .cluster text{fill:#333}#mermaid-svg-PAgcNzrAYYcsdQiU div.mermaidTooltip{position:absolute;text-align:center;max-width:200px;padding:2px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:12px;background:#ffffde;border:1px solid #aa3;border-radius:2px;pointer-events:none;z-index:100}#mermaid-svg-PAgcNzrAYYcsdQiU .actor{stroke:#ccf;fill:#ECECFF}#mermaid-svg-PAgcNzrAYYcsdQiU text.actor>tspan{fill:#000;stroke:none}#mermaid-svg-PAgcNzrAYYcsdQiU .actor-line{stroke:grey}#mermaid-svg-PAgcNzrAYYcsdQiU .messageLine0{stroke-width:1.5;stroke-dasharray:none;stroke:#333}#mermaid-svg-PAgcNzrAYYcsdQiU .messageLine1{stroke-width:1.5;stroke-dasharray:2, 2;stroke:#333}#mermaid-svg-PAgcNzrAYYcsdQiU #arrowhead path{fill:#333;stroke:#333}#mermaid-svg-PAgcNzrAYYcsdQiU .sequenceNumber{fill:#fff}#mermaid-svg-PAgcNzrAYYcsdQiU #sequencenumber{fill:#333}#mermaid-svg-PAgcNzrAYYcsdQiU #crosshead path{fill:#333;stroke:#333}#mermaid-svg-PAgcNzrAYYcsdQiU .messageText{fill:#333;stroke:#333}#mermaid-svg-PAgcNzrAYYcsdQiU .labelBox{stroke:#ccf;fill:#ECECFF}#mermaid-svg-PAgcNzrAYYcsdQiU .labelText,#mermaid-svg-PAgcNzrAYYcsdQiU .labelText>tspan{fill:#000;stroke:none}#mermaid-svg-PAgcNzrAYYcsdQiU .loopText,#mermaid-svg-PAgcNzrAYYcsdQiU .loopText>tspan{fill:#000;stroke:none}#mermaid-svg-PAgcNzrAYYcsdQiU .loopLine{stroke-width:2px;stroke-dasharray:2, 2;stroke:#ccf;fill:#ccf}#mermaid-svg-PAgcNzrAYYcsdQiU .note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-PAgcNzrAYYcsdQiU .noteText,#mermaid-svg-PAgcNzrAYYcsdQiU .noteText>tspan{fill:#000;stroke:none}#mermaid-svg-PAgcNzrAYYcsdQiU .activation0{fill:#f4f4f4;stroke:#666}#mermaid-svg-PAgcNzrAYYcsdQiU .activation1{fill:#f4f4f4;stroke:#666}#mermaid-svg-PAgcNzrAYYcsdQiU .activation2{fill:#f4f4f4;stroke:#666}#mermaid-svg-PAgcNzrAYYcsdQiU .mermaid-main-font{font-family:"trebuchet ms", verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PAgcNzrAYYcsdQiU .section{stroke:none;opacity:0.2}#mermaid-svg-PAgcNzrAYYcsdQiU .section0{fill:rgba(102,102,255,0.49)}#mermaid-svg-PAgcNzrAYYcsdQiU .section2{fill:#fff400}#mermaid-svg-PAgcNzrAYYcsdQiU .section1,#mermaid-svg-PAgcNzrAYYcsdQiU .section3{fill:#fff;opacity:0.2}#mermaid-svg-PAgcNzrAYYcsdQiU .sectionTitle0{fill:#333}#mermaid-svg-PAgcNzrAYYcsdQiU .sectionTitle1{fill:#333}#mermaid-svg-PAgcNzrAYYcsdQiU .sectionTitle2{fill:#333}#mermaid-svg-PAgcNzrAYYcsdQiU .sectionTitle3{fill:#333}#mermaid-svg-PAgcNzrAYYcsdQiU .sectionTitle{text-anchor:start;font-size:11px;text-height:14px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PAgcNzrAYYcsdQiU .grid .tick{stroke:#d3d3d3;opacity:0.8;shape-rendering:crispEdges}#mermaid-svg-PAgcNzrAYYcsdQiU .grid .tick text{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PAgcNzrAYYcsdQiU .grid path{stroke-width:0}#mermaid-svg-PAgcNzrAYYcsdQiU .today{fill:none;stroke:red;stroke-width:2px}#mermaid-svg-PAgcNzrAYYcsdQiU .task{stroke-width:2}#mermaid-svg-PAgcNzrAYYcsdQiU .taskText{text-anchor:middle;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PAgcNzrAYYcsdQiU .taskText:not([font-size]){font-size:11px}#mermaid-svg-PAgcNzrAYYcsdQiU .taskTextOutsideRight{fill:#000;text-anchor:start;font-size:11px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PAgcNzrAYYcsdQiU .taskTextOutsideLeft{fill:#000;text-anchor:end;font-size:11px}#mermaid-svg-PAgcNzrAYYcsdQiU .task.clickable{cursor:pointer}#mermaid-svg-PAgcNzrAYYcsdQiU .taskText.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-PAgcNzrAYYcsdQiU .taskTextOutsideLeft.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-PAgcNzrAYYcsdQiU .taskTextOutsideRight.clickable{cursor:pointer;fill:#003163 !important;font-weight:bold}#mermaid-svg-PAgcNzrAYYcsdQiU .taskText0,#mermaid-svg-PAgcNzrAYYcsdQiU .taskText1,#mermaid-svg-PAgcNzrAYYcsdQiU .taskText2,#mermaid-svg-PAgcNzrAYYcsdQiU .taskText3{fill:#fff}#mermaid-svg-PAgcNzrAYYcsdQiU .task0,#mermaid-svg-PAgcNzrAYYcsdQiU .task1,#mermaid-svg-PAgcNzrAYYcsdQiU .task2,#mermaid-svg-PAgcNzrAYYcsdQiU .task3{fill:#8a90dd;stroke:#534fbc}#mermaid-svg-PAgcNzrAYYcsdQiU .taskTextOutside0,#mermaid-svg-PAgcNzrAYYcsdQiU .taskTextOutside2{fill:#000}#mermaid-svg-PAgcNzrAYYcsdQiU .taskTextOutside1,#mermaid-svg-PAgcNzrAYYcsdQiU .taskTextOutside3{fill:#000}#mermaid-svg-PAgcNzrAYYcsdQiU .active0,#mermaid-svg-PAgcNzrAYYcsdQiU .active1,#mermaid-svg-PAgcNzrAYYcsdQiU .active2,#mermaid-svg-PAgcNzrAYYcsdQiU .active3{fill:#bfc7ff;stroke:#534fbc}#mermaid-svg-PAgcNzrAYYcsdQiU .activeText0,#mermaid-svg-PAgcNzrAYYcsdQiU .activeText1,#mermaid-svg-PAgcNzrAYYcsdQiU .activeText2,#mermaid-svg-PAgcNzrAYYcsdQiU .activeText3{fill:#000 !important}#mermaid-svg-PAgcNzrAYYcsdQiU .done0,#mermaid-svg-PAgcNzrAYYcsdQiU .done1,#mermaid-svg-PAgcNzrAYYcsdQiU .done2,#mermaid-svg-PAgcNzrAYYcsdQiU .done3{stroke:grey;fill:#d3d3d3;stroke-width:2}#mermaid-svg-PAgcNzrAYYcsdQiU .doneText0,#mermaid-svg-PAgcNzrAYYcsdQiU .doneText1,#mermaid-svg-PAgcNzrAYYcsdQiU .doneText2,#mermaid-svg-PAgcNzrAYYcsdQiU .doneText3{fill:#000 !important}#mermaid-svg-PAgcNzrAYYcsdQiU .crit0,#mermaid-svg-PAgcNzrAYYcsdQiU .crit1,#mermaid-svg-PAgcNzrAYYcsdQiU .crit2,#mermaid-svg-PAgcNzrAYYcsdQiU .crit3{stroke:#f88;fill:red;stroke-width:2}#mermaid-svg-PAgcNzrAYYcsdQiU .activeCrit0,#mermaid-svg-PAgcNzrAYYcsdQiU .activeCrit1,#mermaid-svg-PAgcNzrAYYcsdQiU .activeCrit2,#mermaid-svg-PAgcNzrAYYcsdQiU .activeCrit3{stroke:#f88;fill:#bfc7ff;stroke-width:2}#mermaid-svg-PAgcNzrAYYcsdQiU .doneCrit0,#mermaid-svg-PAgcNzrAYYcsdQiU .doneCrit1,#mermaid-svg-PAgcNzrAYYcsdQiU .doneCrit2,#mermaid-svg-PAgcNzrAYYcsdQiU .doneCrit3{stroke:#f88;fill:#d3d3d3;stroke-width:2;cursor:pointer;shape-rendering:crispEdges}#mermaid-svg-PAgcNzrAYYcsdQiU .milestone{transform:rotate(45deg) scale(0.8, 0.8)}#mermaid-svg-PAgcNzrAYYcsdQiU .milestoneText{font-style:italic}#mermaid-svg-PAgcNzrAYYcsdQiU .doneCritText0,#mermaid-svg-PAgcNzrAYYcsdQiU .doneCritText1,#mermaid-svg-PAgcNzrAYYcsdQiU .doneCritText2,#mermaid-svg-PAgcNzrAYYcsdQiU .doneCritText3{fill:#000 !important}#mermaid-svg-PAgcNzrAYYcsdQiU .activeCritText0,#mermaid-svg-PAgcNzrAYYcsdQiU .activeCritText1,#mermaid-svg-PAgcNzrAYYcsdQiU .activeCritText2,#mermaid-svg-PAgcNzrAYYcsdQiU .activeCritText3{fill:#000 !important}#mermaid-svg-PAgcNzrAYYcsdQiU .titleText{text-anchor:middle;font-size:18px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PAgcNzrAYYcsdQiU g.classGroup text{fill:#9370db;stroke:none;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family);font-size:10px}#mermaid-svg-PAgcNzrAYYcsdQiU g.classGroup text .title{font-weight:bolder}#mermaid-svg-PAgcNzrAYYcsdQiU g.clickable{cursor:pointer}#mermaid-svg-PAgcNzrAYYcsdQiU g.classGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-PAgcNzrAYYcsdQiU g.classGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-PAgcNzrAYYcsdQiU .classLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.5}#mermaid-svg-PAgcNzrAYYcsdQiU .classLabel .label{fill:#9370db;font-size:10px}#mermaid-svg-PAgcNzrAYYcsdQiU .relation{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-PAgcNzrAYYcsdQiU .dashed-line{stroke-dasharray:3}#mermaid-svg-PAgcNzrAYYcsdQiU #compositionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-PAgcNzrAYYcsdQiU #compositionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-PAgcNzrAYYcsdQiU #aggregationStart{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-PAgcNzrAYYcsdQiU #aggregationEnd{fill:#ECECFF;stroke:#9370db;stroke-width:1}#mermaid-svg-PAgcNzrAYYcsdQiU #dependencyStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-PAgcNzrAYYcsdQiU #dependencyEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-PAgcNzrAYYcsdQiU #extensionStart{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-PAgcNzrAYYcsdQiU #extensionEnd{fill:#9370db;stroke:#9370db;stroke-width:1}#mermaid-svg-PAgcNzrAYYcsdQiU .commit-id,#mermaid-svg-PAgcNzrAYYcsdQiU .commit-msg,#mermaid-svg-PAgcNzrAYYcsdQiU .branch-label{fill:lightgrey;color:lightgrey;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PAgcNzrAYYcsdQiU .pieTitleText{text-anchor:middle;font-size:25px;fill:#000;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PAgcNzrAYYcsdQiU .slice{font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PAgcNzrAYYcsdQiU g.stateGroup text{fill:#9370db;stroke:none;font-size:10px;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PAgcNzrAYYcsdQiU g.stateGroup text{fill:#9370db;fill:#333;stroke:none;font-size:10px}#mermaid-svg-PAgcNzrAYYcsdQiU g.statediagram-cluster .cluster-label text{fill:#333}#mermaid-svg-PAgcNzrAYYcsdQiU g.stateGroup .state-title{font-weight:bolder;fill:#000}#mermaid-svg-PAgcNzrAYYcsdQiU g.stateGroup rect{fill:#ECECFF;stroke:#9370db}#mermaid-svg-PAgcNzrAYYcsdQiU g.stateGroup line{stroke:#9370db;stroke-width:1}#mermaid-svg-PAgcNzrAYYcsdQiU .transition{stroke:#9370db;stroke-width:1;fill:none}#mermaid-svg-PAgcNzrAYYcsdQiU .stateGroup .composit{fill:white;border-bottom:1px}#mermaid-svg-PAgcNzrAYYcsdQiU .stateGroup .alt-composit{fill:#e0e0e0;border-bottom:1px}#mermaid-svg-PAgcNzrAYYcsdQiU .state-note{stroke:#aa3;fill:#fff5ad}#mermaid-svg-PAgcNzrAYYcsdQiU .state-note text{fill:black;stroke:none;font-size:10px}#mermaid-svg-PAgcNzrAYYcsdQiU .stateLabel .box{stroke:none;stroke-width:0;fill:#ECECFF;opacity:0.7}#mermaid-svg-PAgcNzrAYYcsdQiU .edgeLabel text{fill:#333}#mermaid-svg-PAgcNzrAYYcsdQiU .stateLabel text{fill:#000;font-size:10px;font-weight:bold;font-family:'trebuchet ms', verdana, arial;font-family:var(--mermaid-font-family)}#mermaid-svg-PAgcNzrAYYcsdQiU .node circle.state-start{fill:black;stroke:black}#mermaid-svg-PAgcNzrAYYcsdQiU .node circle.state-end{fill:black;stroke:white;stroke-width:1.5}#mermaid-svg-PAgcNzrAYYcsdQiU #statediagram-barbEnd{fill:#9370db}#mermaid-svg-PAgcNzrAYYcsdQiU .statediagram-cluster rect{fill:#ECECFF;stroke:#9370db;stroke-width:1px}#mermaid-svg-PAgcNzrAYYcsdQiU .statediagram-cluster rect.outer{rx:5px;ry:5px}#mermaid-svg-PAgcNzrAYYcsdQiU .statediagram-state .divider{stroke:#9370db}#mermaid-svg-PAgcNzrAYYcsdQiU .statediagram-state .title-state{rx:5px;ry:5px}#mermaid-svg-PAgcNzrAYYcsdQiU .statediagram-cluster.statediagram-cluster .inner{fill:white}#mermaid-svg-PAgcNzrAYYcsdQiU .statediagram-cluster.statediagram-cluster-alt .inner{fill:#e0e0e0}#mermaid-svg-PAgcNzrAYYcsdQiU .statediagram-cluster .inner{rx:0;ry:0}#mermaid-svg-PAgcNzrAYYcsdQiU .statediagram-state rect.basic{rx:5px;ry:5px}#mermaid-svg-PAgcNzrAYYcsdQiU .statediagram-state rect.divider{stroke-dasharray:10,10;fill:#efefef}#mermaid-svg-PAgcNzrAYYcsdQiU .note-edge{stroke-dasharray:5}#mermaid-svg-PAgcNzrAYYcsdQiU .statediagram-note rect{fill:#fff5ad;stroke:#aa3;stroke-width:1px;rx:0;ry:0}:root{--mermaid-font-family: '"trebuchet ms", verdana, arial';--mermaid-font-family: "Comic Sans MS", "Comic Sans", cursive}#mermaid-svg-PAgcNzrAYYcsdQiU .error-icon{fill:#522}#mermaid-svg-PAgcNzrAYYcsdQiU .error-text{fill:#522;stroke:#522}#mermaid-svg-PAgcNzrAYYcsdQiU .edge-thickness-normal{stroke-width:2px}#mermaid-svg-PAgcNzrAYYcsdQiU .edge-thickness-thick{stroke-width:3.5px}#mermaid-svg-PAgcNzrAYYcsdQiU .edge-pattern-solid{stroke-dasharray:0}#mermaid-svg-PAgcNzrAYYcsdQiU .edge-pattern-dashed{stroke-dasharray:3}#mermaid-svg-PAgcNzrAYYcsdQiU .edge-pattern-dotted{stroke-dasharray:2}#mermaid-svg-PAgcNzrAYYcsdQiU .marker{fill:#333}#mermaid-svg-PAgcNzrAYYcsdQiU .marker.cross{stroke:#333} :root { --mermaid-font-family: "trebuchet ms", verdana, arial;} #mermaid-svg-PAgcNzrAYYcsdQiU { color: rgba(0, 0, 0, 0.75); font: ; } twitter_login twitter_list tweettwitter_login
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>ch06 : twitter_login.jsp</title> </head> <body> <div align="center"> <H2>twitter login</H2> <form name="form1" method="POST" action="twitter_list.jsp"> <input type="text" name="username"/> <input type="submit" value="Login"/> </form> </div> </body> </html>twieet
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.*, java.text.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <% // 编码声明 request.setCharacterEncoding("UTF-8"); // 用于传达HTML表格中输入的信息 String msg = request.getParameter("msg"); // 获得session存储的登录的使用者姓名 Object username = session.getAttribute("user"); // 为了存储信息从 application 把用 msgs 存储的ArrayList 带过来 ArrayList<String> msgs = (ArrayList<String>)application.getAttribute("msgs"); // null 则新生产 ArrayList if(msgs == null) { msgs = new ArrayList<String>(); // 把ArrayList 存到application application.setAttribute("msgs",msgs); } // User的姓名,输入消息,日期等信息存储到Arraylist中 Date date = new Date(); SimpleDateFormat f = new SimpleDateFormat("E MMM dd HH:mm", Locale.CHINA); msgs.add(username+" :: "+msg+" , "+ f.format(date)); // 通过tomcat的console控制台记录下来 application.log(msg+"Added"); // 重新跳转到目录页 response.sendRedirect("twitter_list.jsp"); %>twitter_list
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" import="java.util.*"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <% // 编码准备 request.setCharacterEncoding("UTF-8"); // HTML 表格中输入的 username调入 String username = request.getParameter("username"); // username非空时将值存入session if(username != null) { session.setAttribute("user",username); } %> <html> <head> <title>ch06 : twitter_list.jsp</title> </head> <body> <div align=center> <H3>My Simple Twitter!!</H3> <HR> <form action="tweet.jsp" method="POST"> <!-- print session name --> @<%=session.getAttribute("user") %> <input type="text" name="msg"><input type="submit" value="Tweet"> </form> <HR> <div align="left"> <UL> <% // 通过application内置对象把msgs存储的ArrayList调入 ArrayList<String>msgs = (ArrayList<String>)application.getAttribute("msgs"); //msgs不是null的话则输出下面内容 if(msgs != null) { for(String msg : msgs) { out.println("<LI>"+msg+"</LI>"); } } %> </UL> </div> </div> </body> </html>登录后的用户输出的值对于其他用户也是可见的,使用application的公用存储空间进行操作。