会话(session)
会话他是一个作用域,可以存值,可以取值,session的id一样,就是同一个会话,不一样,就不是同一个会话
实现session有两种形式
cookies(默认)
cookie被禁用,url重写
当cookie被禁用,session不好使了,在提交的后面加一个;jsessionid=session.getid
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n128" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">
<textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="box-sizing: border-box; overflow: auto; color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; margin: 0px; position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">//获取session</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">HttpSession session = request.getSession();</pre>
</pre>
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n129" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">
<textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="box-sizing: border-box; overflow: auto; color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; margin: 0px; position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">session.isNew()</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">返回值true,false,判断这个session是不是新的会话</pre>
</pre>
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n130" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">
<textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="box-sizing: border-box; overflow: auto; color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; margin: 0px; position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">//session设置会话有效时间</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">session.setMaxInactiveInterval(60*60);</pre>
</pre>
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n131" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">
<textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="box-sizing: border-box; overflow: auto; color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; margin: 0px; position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">//会话最后访问时间</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">session.getLastAccessedTime()</pre>
</pre>
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n132" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">
<textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="box-sizing: border-box; overflow: auto; color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; margin: 0px; position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">//会话创建时间</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">session.getCreationTime()</pre>
</pre>
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n133" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">
<textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="box-sizing: border-box; overflow: auto; color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; margin: 0px; position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">//获取会话有效时间</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">session.getMaxInactiveInterval()</pre>
</pre>
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n134" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">
<textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="box-sizing: border-box; overflow: auto; color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; margin: 0px; position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">//获取Id</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">session.getId()</pre>
</pre>
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n135" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">
<textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="box-sizing: border-box; overflow: auto; color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; margin: 0px; position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">//添加,第二个值是object类型</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">session.setAttribute("count",count);</pre>
</pre>
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n136" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">
<textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="box-sizing: border-box; overflow: auto; color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; margin: 0px; position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">//获取 返回值object</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">session.getAttribute("count")</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"></pre>
</pre>
servlet2.5,3.0区别
2.5要在web.xml中配置,3.0不用,但得写注解,2.5配置文件会越来越多
jsp
servlet缺点:写html代码费劲,写java代码方便(java代码里嵌入html)
jsp:就是一个servlet,是servlet升级版,写html方便(html里嵌入java代码)
嵌入java代码用<% %>
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n151" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">
<textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="box-sizing: border-box; overflow: auto; color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; margin: 0px; position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"><%</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"> Date time=new Date();</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">out.print("<h3>time:"+time+"<h3>");</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">%></pre>
</pre>
当你第一次使用jsp时,速度略微慢点
jsp编译过程:先编译成servlet,在编译成.class文件,在运行在虚拟机上.
jsp注释:
使用“//”对单行代码进行注释
使用“/* */”方式对多行代码进行注释
使用“/** */”方式对多行代码进行注释
使用“<%-- --%>”对多行代码进行注释(客户端不能查看到 )
使用“”对多行HTML代码进行注释这(客户端可以查看到)
指令
page指令:
include指令
include 指令用于在运行时将 HTML文件或 JSP页面嵌入到另一个 JSP页面 "
<%@ include file = "/foot.jsp" %>
声明的概念
JSP声明就是在JSP页面中声明Java方法
1:<%!public int x=10;%>(声明标记:声明一个属性,方法,以后不用,用了就错了)
2:标记:书写java代码的地方
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n185" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">
<textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="box-sizing: border-box; overflow: auto; color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; margin: 0px; position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"><% </pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">String name="哈哈";</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">int count=100;</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">%></pre>
</pre>
3:输出标记
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n188" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">
<textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="box-sizing: border-box; overflow: auto; color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; margin: 0px; position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"><h1>输出标记:</h1></pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"><h3>name:<%=name %></h3></pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"><h3>count:<%=count+10 %></h3></pre>
</pre>
jsp隐式对象
request
也是一个域,可以传值到jsp
request.setAttribute()
第一个参数字符串,第二个object类型
request.getAttribute()
参数是字符串,返回值是object类型
request.getContextPath()工程目录
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n205" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">
<textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="box-sizing: border-box; overflow: auto; color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; margin: 0px; position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"><%=request.getContextPath() %>/index.jsp</pre>
</pre>
2种跳转页面方法,第二种request值可以传过去this.findAll(request, response);
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n209" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">
<textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="box-sizing: border-box; overflow: auto; color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; margin: 0px; position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">//跳转url地址栏不是最终地址,是servlet地址,可以把request作用域里面的值传过去</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"></pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">request.getRequestDispatcher("MessageServlet?method=findAll").forward(request, response);</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"></pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">//地址栏是最终地址栏,request作用域里的值传不过去,还可以跳站外资源(例如百度)</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"></pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">response.sendRedirect("MessageServlet?method=findAll");</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"></pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">//第二种跳转链接可以传值,第二个页面可以拿到。</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"></pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">//跳servlet时,不一定调用dopost,还是doget,看根源处走的是什么</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"></pre>
</pre>
隐式对象
输入输出:request ,response,out
作用域通信:session,application,PageContext
Servlet对象:page(Object类型对象)config(配置文件信息)
错误对象:exception
application:作用于整个应用服务器的全局作用域
request:出了这个请求响应就不能用
session:不是一个ID就不能用
pageContext:当前页面作用域
错误
04(路径错误)
500(代码错误)
401(验证错误)
405(doPost/doGet方法不全)
编写显示错误的页面
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n241" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">
<textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="box-sizing: border-box; overflow: auto; color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; margin: 0px; position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">//在web.xml文件中配置,写jsp错误页面,location里面是jsp文件路径</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"><error-page></pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"> <error-code>404</error-code></pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"> <location>/error404.jsp</location></pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"> </error-page></pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"> <error-page></pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"> <error-code>500</error-code></pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"> <location>/error500.jsp</location></pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"> </error-page></pre>
</pre>
Jsp El
1.减少JSP页面中Java代码
2.方便JSP中代码的修改,也方便美工修改页面外观
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n250" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">
<textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="box-sizing: border-box; overflow: auto; color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; margin: 0px; position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"><h3>10+10=<%=10+10 %></h3></pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"><h3>10+10=${10+10 }</h3></pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">效果差不多</pre>
</pre>
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n251" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">
<textarea autocorrect="off" autocapitalize="off" spellcheck="false" tabindex="0" style="box-sizing: border-box; overflow: auto; color: inherit; font-style: inherit; font-variant: inherit; font-weight: inherit; font-stretch: inherit; font-size: inherit; line-height: inherit; font-family: inherit; margin: 0px; position: absolute; bottom: -1em; padding: 0px; width: 1000px; height: 1em; outline: none;"></textarea>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"><h3>name=<%=x %></h3> //x是get取到的</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"><h3>name2=${name }</h3>//前面的set方法第一个参数叫name</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;">//u是set的第一个参数,第二个参数是u这个对象,el表达式可以支架用第一个参数点出对象中的属性</pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"><h3>username:${u.username }</h3></pre>
<pre class=" CodeMirror-line " role="presentation" style="box-sizing: border-box; overflow: visible; font-family: inherit; font-size: inherit; white-space: pre-wrap; line-height: 1.71429em; break-inside: avoid; padding: 0px 4px; border-radius: 0px; border-top-width: 0px; border-right: none; border-bottom-width: 0px; border-left-width: 0px; background: 0px 0px; margin: 0px; word-wrap: break-word; color: inherit; z-index: 2; position: relative; word-break: normal; width: inherit;"><h3>pwd:${u.pwd }</h3></pre>
</pre>
[图片上传失败...(image-a1653d-1576216451512)]
JSP EL的内置对象
requestScope
sessionScope
applicationScope
param
paramValues
el表达式读取顺序
page-request-session-application
当四个域的set方法存的第一个参数一样时,有固定的读取顺序
<pre class="md-fences mock-cm md-end-block" lang="" contenteditable="false" cid="n271" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre-wrap; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">//内置对象的用法,固定读取
<h3>name:{sessionScope.name};</h3>
<h3>name:${applicationScope.name};</h3>
</pre><pre class="md-fences mock-cm md-end-block" lang="" contenteditable="false" cid="n272" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre-wrap; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 0px; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">//同request.getParmeter("name")
<h3>name4:${param.name};</h3>
</pre>
MVC
是一种编程的思想,包括M V C ,m:数据模型。V:显示层 C:控制层,能使各层都分开,便于我们日常的分工合作,但能增加一点代码的复杂度
定制标记库
增加表现层的处理能力
减少JSP文件中的Java代码
定制标记的作用类似
<pre class="md-fences mock-cm md-end-block" lang="" contenteditable="false" cid="n285" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre-wrap; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">//导入标记库
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
</pre>1.set标签,可以向不同的作用域里传值
<pre class="md-fences mock-cm md-end-block" lang="" contenteditable="false" cid="n290" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre-wrap; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;"><c:set var="name2" scope="session" value="session里面的值"></c:set>
</pre>2.放在catch标签里,即使错误,程序也能继续运行
<pre class="md-fences mock-cm md-end-block" lang="" contenteditable="false" cid="n293" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre-wrap; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;"><c:catch var="e">
<%
int p=Integer.parseInt(request.getParameter("page")) ;%>
<h3>page=<%=p %></h3></c:catch>
//错误信息
<h3>e=${e}</h3>
</pre>3.if标签,跟if语句一样,没有else
<pre class="md-fences mock-cm md-end-block" lang="" contenteditable="false" cid="n296" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre-wrap; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;"><c:if test="{ not empty name3 }">
<h3>name3里面不为空name3=${name3}</h3></c:if>
</pre>4.choose标签,和when标签一起使用,相当于else if,otherwide标签相当于else
<pre class="md-fences mock-cm md-end-block" lang="" contenteditable="false" cid="n299" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre-wrap; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;"><c:choose>
<c:when test="{param.p<50 }">
<h3>p小于50</h3>
</c:when>
<c:otherwise><h3>p不小于50</h3>
</c:otherwise>
</c:choose>
</pre>5循环.标签,从1开始,没回走2,走到10
<pre class="md-fences mock-cm md-end-block" lang="" contenteditable="false" cid="n302" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre-wrap; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;"><c:forEach begin="1" end="10" var="i" step="2" varStatus="s">
i={s.count }
</c:forEach>
</pre>6.forTokens标签,以逗号分割
<pre class="md-fences mock-cm md-end-block" lang="" contenteditable="false" cid="n305" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre-wrap; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 0px; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;"><%
request.setAttribute("aihao", "吃,喝,玩,乐");
%>
<c:forTokens items="{s.index}==>${a }
</c:forTokens>
</pre>
Servlet监听器
在Web应用中响应特定对象的特定事件
1.更加方便的控制application、session 和request 对象的发生的特定事件。
2.可以集中处理特定的事件。
<pre class="md-fences mock-cm md-end-block" lang="" contenteditable="false" cid="n314" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre-wrap; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;"> session.invalidate();
//关闭session
</pre><pre class="md-fences mock-cm md-end-block" lang="" contenteditable="false" cid="n315" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre-wrap; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">//当前页面有session,就用当前session,没有也不创建session
<%@page session="false" %>
</pre>servlet监听器创建过程
需要配置web.xml文件
<pre class="md-fences mock-cm md-end-block" lang="" contenteditable="false" cid="n320" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre-wrap; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;"><listener>
<listener-class>com.neusoft.listener.CountListener</listener-class>
</listener>
</pre><pre class="md-fences mock-cm md-end-block" lang="" contenteditable="false" cid="n321" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre-wrap; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">package com.neusoft.listener;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;public class CountListener implements HttpSessionListener {
public static int count=0;@Override
public void sessionCreated(HttpSessionEvent arg0) {
// TODO Auto-generated method stubcount++; System.out.println("创建 count="+count);
}
@Override
public void sessionDestroyed(HttpSessionEvent arg0) {
// TODO Auto-generated method stu
count--;
System.out.println("销毁 count="+count);}
}
</pre>
<pre class="md-fences mock-cm md-end-block" lang="" contenteditable="false" cid="n322" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre-wrap; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">package com.neusoft.listener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;public class MyListener implements HttpSessionAttributeListener {
@Override
public void attributeAdded(HttpSessionBindingEvent arg0) {
System.out.println("添加");}
@Override
public void attributeRemoved(HttpSessionBindingEvent arg0) {
System.out.println("移除");}
@Override
public void attributeReplaced(HttpSessionBindingEvent arg0) {
System.out.println("替换");}
}
</pre>
Servlet过滤器
Filter接口,需要实现这个接口,有初始化,执行,销毁3个方法
初始化:在启动服务时调用
执行:在进入另一个窗口时调用
销毁:在关闭服务式调用
需要配置web.xml文件
<pre class="md-fences mock-cm md-end-block" lang="" contenteditable="false" cid="n337" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre-wrap; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;"><filter>
<filter-name>正常写文件名</filter-name>
<filter-class>cm.neusoft.filter.MyFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>正常写文件名</filter-name>
<url-pattern>/</url-pattern>
// /代表所有都过滤,即使地址写错了,或者没有这个地址,也都会过滤
</filter-mapping>
</pre><pre class="md-fences mock-cm md-end-block" lang="" contenteditable="false" cid="n338" mdtype="fences" style="box-sizing: border-box; overflow: visible; font-family: var(--monospace); font-size: 0.9rem; white-space: pre-wrap; line-height: 1.71429em; text-align: left; break-inside: avoid; display: block; background-image: inherit; background-position: inherit; background-size: inherit; background-repeat: inherit; background-attachment: inherit; background-origin: inherit; background-clip: inherit; background-color: rgb(218, 218, 218); position: relative !important; margin-bottom: 3em; padding-left: 1ch; padding-right: 1ch; margin-left: 2em; width: inherit;">package cm.neusoft.filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;public class MyFilter implements Filter{
@Override
public void destroy() {
System.out.println("销毁");}
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
System.out.println("执行");
/*
- 如果有下一个filter,执行下一个filter
- 如果没有下一个filter,执行原请求
*/
chain.doFilter(request, response);
}@Override
public void init(FilterConfig arg0) throws ServletException {
System.out.println("初始化");}
}
</pre>
由一个jsp跳到一个servlet,然后这个servlet以.forward跳到另一个jsp或者servlet里面,下一个jsp或者servlet不会被拦截(不会被过滤)。
当跳转的时候,以sendRedirect进行跳转的时候,无脑被过滤,以.forward跳转的时候,跳转的界面不会被过滤