1.JSP

<%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">

<title>My JSP 'index.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>

<body>
This is my JSP page. <br>
</body>
</html>

1.<%@ %> JSP标签

2.jsp有三大指令

<%@ page language="java" import="java.util.*" contentType="text/html; charset=GBK" pageEncoding="ISO-8859-1"%>
<%@ include file="" %>
<%@ taglib uri="" prefix="" %>

3.jsp内置9大对象

request , response , session , cookie , pageContext , application , config , out,page

4.jsp的两种输出

<%out.print("aa");%>
<%="aa"%>

5.jsp动作

6.全局变量

<%! int i=1%>

在尖括号后面加上叹号,则代表全局变量,所有登陆系统的用户都会使用这同一个i

7.表单的参数传递
1.jsp

<%@ page pageEncoding="GBK" %>
<html>
<head>
</head>

<body>
<form action="do_1.jsp">
用户名:<input type="text" name="userName"/><br/>
密码:<input type="password" name="passWord"><br>
确认密码:<input type="password" name="passWord1"><br/>
性别:<input type="radio" name="sex" value="1" checked="checked"/>
<input type="radio" name="sex" value="2" /><br/>
<input type="submit" value="提交">
</form>
</body>
</html>

do_1.jsp

<%@ page  pageEncoding="GBK"%>
<%
String userName=request.getParameter("userName");
String passWord=request.getParameter("passWord");
String passWord1=request.getParameter("passWord1");
String sex=request.getParameter("sex");
//if(userName==null||userName.equals("")){
//out.println("用户名不能为空,请<a href='javascript:history.back()'>返回</a>");
//return;
//}
if("".equals(userName)){
out.println("用户名不能为空,请<a href='javascript:history.back()'>返回</a>");
return;
}
if(!passWord.equals(passWord1)){
out.println("两次密码不一致,请<a href='javascript:history.back()'>返回</a>");
return;
}

%>
姓名:<%=userName%><br/>
密码:<%=passWord%><br/>
性别:<%=(sex.equals("1")?"男":"女")%>


8.表单的GET和POST两种提交方式

如果1.jsp是POST提交可以在do_1.jsp中写上 request.setCharacterEncoding("GBK");进行转码

如果1.jsp是GET提交可以在do_1.jsp中String love=new String(request.getParameter("").getBytes("iso8859-1"),"GBK");这种方式进行转码(这种方法通用于GET/POST)

9.jsp有四种属性范围:

  page=页面级别(只在当前页面生效)

     request=请求级别(客户机和服务器一次交互) 

   session =会话级别(一起回话可能是多次请求,IE不关闭就属于一次会话)

     application=应用级别(登陆在网上的所有人都使用这同一个属性)

10.JSP动作

  <jsp:forward page=""/>容器内跳转(服务器跳转),相对的有客户端跳转

  <jsp:include flush="true" page=""></jsp:include> include动作与include指令是有区别的 include动作先将页面解析再包含,而include指令则是先包含再解析,所以有时候会有变量冲突 (动态包含和静态包含的区别)

  静态包含可以包含任意的文件<%@ include file="inc.txt"%>

  动态包含只能包含jsp文件

11.页面跳转

  客户端跳转:

  response.sendRedirect("");//自动跳转

  <meta http-equiv="refresh" content="3;url=2.jsp">

  javascript;history.back();

  response.setHeader("refresh","3;url=2.jsp");
  服务器跳转:

  <jsp:forward page=""/>

  pageContext.forward();

12.<jsp:useBean id="" class=""/>

  <jsp:setProperty property="" name=""/>




posted @ 2011-12-27 18:14  陈鹏C  阅读(304)  评论(0编辑  收藏  举报