get:点击网址,超链接,method后面写get,查询最大255字符,是以明文形式进行传输的,传输不了中文(传中文得处理,有的浏览器可能会自动处理)。
post:method后面写post,不是以明文的形式进行传输,相对来说安全,post传输的数据量没有大小限制.
web应用程序使用三层体系结构
数据层:数据库
业务层:web服务器
表示层:客户端
开发工具
eclipse:免费
Myeclipse:收费
idea:收费
主流的Java Web应用服务器
Tomcat:免费
JBoss:收费
WebLogic Server:收费
lib目录:存放部署Java类库
bin目录:存放与Tomcat运行有关的类、类库和DOS的批处理文件
webapps:部署WEB项目
什么是 Servlet ?
Servlet 是一个java类,能运行在服务器上,处理客户端发送过来的请求(get,post)
servlet生命周期
servlet是以单例的模式完成的,构造器调用一回。
init:只有在第一次访问servlet 时调用初始化
service:有doget(),和dopost()方法
destory:结束服务器的时候调用
request 请求
response 响应
request.getParameter("表单元素名字);返回值是表单的值
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n66" 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;">String name = request.getParameter("useName");</pre>
</pre>
request.getParameterValues(表单元素名字);返回值是一个数组,例如复选框
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n71" 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;">String[] aihao = request.getParameterValues("aihao");</pre>
</pre>
控制台中文问题解决 ,传输过程中的问题,取表单中元素
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n76" 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.setCharacterEncoding("utf-8");</pre>
</pre>
页面中文问题解决
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n81" 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;">response.setContentType("text/html;charset=utf-8");</pre>
</pre>
response.getWriter();返回一个PrintWriter对象,对象.write(),可以在页面输入
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n86" 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;"> PrintWriter out = response.getWriter();</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.write("<html>");</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.write("<title>标题</title>");</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.write("<body>");</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.write("<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;"> out.write("<h1>用户名:"+name+"</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;"> out.write("<h1>性别:"+sex+"</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;"> out.write("<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;"> for (int i = 0; i < aihao.length; i++) {</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.write(aihao[i]+" ");</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;"> out.write("</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;"> out.write("</body>");</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.write("</html>");</pre>
</pre>
超链接也是可以传值的
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n89" 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><a href="servlet/MyServlet?useName=aaaa1&aihao=chi&aihao=he">超链接传一个值</a></h3></pre>
</pre>
调到另一个servlet
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n92" 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.getRequestDispatcher("FindAll").forward(request, response);</pre>
</pre>
防止添加东西加入js代码等恶意代码,写一个工具包,里面写一个类加入这个方法
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n95" 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;">public static String htmlfilter(String input) {</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;"> if (input == null) {</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;"> return null;</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;"> if (input.length() == 0) {</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;"> return input;</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;"> input = input.replaceAll("&", "&");</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;"> input = input.replaceAll("<", "<");</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;"> input = input.replaceAll(">", ">");</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;"> input = input.replaceAll(" ", " ");</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;"> input = input.replaceAll("'", "'");</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;"> input = input.replaceAll(""", """);</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;"> input = input.replaceAll("\n", "
");</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;"> return input;</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>
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n96" 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;">m.setTxt(Tools.htmlfilter(area));</pre>
</pre>
数据库连接池
提高我们的数据库并发访问能力,不能从根本上解决
假如支持1秒钟100个并发访问(最大并发访问量),先一直开30个连接(最大空闲数),有人访问就给他,如果超过30个,就在开新的连接,如果超过100个,后面的排队,等前面的连接用完。
Cookie
是存在于客户端,浏览器所在的那块硬盘上的一个文本文件,是以键值对(键值都是字符串)的形式存储的
例如论坛记住密码1周,1天都是存在COOkie里,在登录的时候,在要求的时间里都自动登录
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n111" 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;">//添加一个Cookie</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;">Cookie c=new Cookie("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;"> //cookie保存时间</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;"> c.setMaxAge(60*60);</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;"> //把cookie写入文本文件</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.addCookie(c);</pre>
</pre>
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n112" 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;">查找Cookie</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;">Cookie[] cookies = request.getCookies();</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;"> Cookie c =null;</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;"> if(cookies!=null){</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;"> for(int i= 0; i < cookies.length; i++) {</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;"> c = cookies[i];</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;"> System.out.println("key:"+c.getName());</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;"> System.out.println("value:"+c.getValue());</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>
存取cookie value值得中文处理
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n114" 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;">//(存值)value写中文添加,报500错误,需要做value中文处理</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 key=request.getParameter("key");</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 value=request.getParameter("value");</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 value_utf8 = java.net.URLEncoder.encode(value,"utf-8"); </pre>
</pre>
<pre class="md-fences md-end-block" lang="" contenteditable="false" cid="n115" 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 value_utf8=java.net.URLDecoder.decode(c.getValue(), "utf-8");</pre>
</pre>