0701-Jsp基础知识小结

---------------------------------JS-----------------------------------------------------------------------

一、应用js的目的:

1、表单验证:减轻服务器压力

2、页面动态效果

3、事件驱动,还很安全。


二、JavaScript组成

1、ECMAScript    Dom   Bom


2、外部引用js

<script type="text/javascript" src="shopping.js"></script>

3、html中直接使用

<input type="button" onclick="javaScript:alert('hello,world!')" value="Hello">

-----------------JSP--------------------------------------------------------------------------------------------------------


1、多次执行的Sql语句,可以用PrepareStatement对象处理。注意:多次。因为它第一次会编译,所以会变快。

2、数据类型为CLOB类型,可视为String类型进行设置。


3、日期类型

setTimestamp


4、全局变量

<%! String name="Tom" %>


5、转义字符

/:请加在需要输出的特殊字符的前面即可。


6、中文乱码

1)页面上

<%
     request.setCharacterEncoding("utf-8");
     response.setCharacterEncoding("utf-8");
%>

2)Tomcat\conf\server.xml文件

...redirectPort=8443URLEncoding="UTF-8"/>


7、Post、Get

post:安全

Get:url显示并可传播,方便转发。

一般用post


8、重定向与转发

重定向:不保留(在客户端,可看到新的url)

转发:全带走(在服务端,forward()方法,服务器内部流转,url不变化,前边没人知道)


9、Session

  1)session是可以设定有效期的。也可以清除某个属性。

    1.1)程序主动清除

     session.invalidate();

     session.removeAttribute("username");

    1.2)服务器主动清除

      setMatInactiveInteral(int interval); //单位是秒

      还可在tomcat服务器的web.xml中的session_config中设定。 //这个单位是分,不是秒。


   2)session中可以保存一个对象object

session.setAttribute("connection",conn);

Object ob_value= session.getAttribute("connection");
if (ob_value==null){...}

10.cookie
保存的是字符串,不是对象
Cookie cookie1=new Cookie("user","Tom"); 
response.addCookie(cookie1);  //发送给服务器保管
在服务端读取时,是一个数组,要判断一下是否非空
Cookie[] cookies =request.getCookies();

11.application

全局变量,会保存下来。

<%!String Title="国家开发管理系统";%>
<%
  Object count=application.getAttribute("count"); //网站访问人数
  if (count==null){
      application.setAttribute("count",new Integer(1));  //存放的是对象
  }else{
      Integer i=(Integer)count;
      application.setAttribute("count",i.intValue()+1); //取出要强转
  }
  Integer iCount = (Integer)application.getAttribute("count");
%>
<footer>
  <%
    out.print("页面被访问了"+ iCount.toString()+"次" );
  %>
</footer>

12.Page

pageContext.setAttribute("name",name);



13、不同作用域的对比

page

request

session

application









猜你喜欢

转载自blog.csdn.net/golden_soft/article/details/80871551