2019-12-13

会话(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:{requestScope.name};</h3> <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="{empty name3 }"> <h3>name3里面为空</h3> </c:if> <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<10 }"> <h3>p小于10</h3> </c:when> <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={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="{aihao }" delims="," var="a" varStatus="s">{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 stub

  count++;
  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跳转的时候,跳转的界面不会被过滤

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,053评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,527评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,779评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,685评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,699评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,609评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,989评论 3 396
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,654评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,890评论 1 298
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,634评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,716评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,394评论 4 319
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,976评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,950评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,191评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,849评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,458评论 2 342

推荐阅读更多精彩内容