笔记代码 1、全局变量:<%! 、全局变量: // 全局变量 // 不加!表示局部变量 不加! int i = 0 ; %> <%=++i%> 2、日期现出:<%=new Date()%> 、日期现出: 3、表格打出:a。<% 、表格打出: 。 // 打印 9×9 的表格 × out.println("
") ; for(int i=0;i<9;i++) { out.println("") ; for(int j=0;j<9;j++) { out.println(""+i*j+" | ") ; } out.println("
") ; } out.println("
") ; %>
b.<% . // 打印 9×9 的表格 × for(int i=0;i<9;i++) { %>
<% for(int j=0;j<9;j++) { %> <%=i*j%> | <% } %>
<% } %> C.<% . // 接收参数 接收参数 String t_row = request.getParameter("rownum") ; String t_col = request.getParameter("colnum") ;
// 将字符串变为整数 int row = 0 ; int col = 0 ; try { row = Integer.parseInt(t_row) ; col = Integer.parseInt(t_col) ; } catch(Exception e) { %> Input Error!!! <% } %>
<% // 打印 9×9 的表格 × for(int i=0;i
<% for(int j=0;j <%=i*j%> | <% } %>
<% } %>
4 页面跳转接受:<% 页面跳转接受: String name = "LiXingHua" ; %>
"/> <%=request.getParameter("ref1")%>
<%=request.getParameter("ref2")%>
5、包含语句:
、包含语句: 6、application 属性:<% 、 属性: application.setAttribute("name","MLDN") ; application.setAttribute("password","LXH") ; %>
、 、 <% String name = (String)application.getAttribute("name") ; String password =
(String)application.getAttribute("password") ; %>
name : <%=name%>
password : <%=password%>
7、pagecontext 属性:<% 、 属性: pageContext.setAttribute("name","MLDN") ; pageContext.setAttribute("password","LXH") ; %>
<% String name =
(String)pageContext.getAttribute("name") ; String password =
(String)pageContext.getAttribute("password") ; %>
name : <%=name%>
password : <%=password%>
<% pageContext.setAttribute("name","MLDN",PageContex t.APPLICATION_SCOPE) ; 另 外
pageContext.setAttribute("password","LXH",PageContext. APPLICATION_SCOPE) ; %>
8、request 属性:<% 、 属性: request.setAttribute("name","MLDN") ; request.setAttribute("password","LXH") ; %>
<% String name = (String)request.getAttribute("name") ; String pass
word =
(String)request.getAttribute("password") ; %>
name : <%=name%>
password : <%=password%>
.jsp">requestDemo03.jsp 9、session 属性:<% 、 属性: session.setAttribute("name","MLDN") ; session.setAttribute("password","LXH") ; %>
% String name = (String)session.getAttribute("name") ; String password =
(String)session.getAttribute("password") ;
%>
name : <%=name%>
password : <%=password%>
sessionDemo03.jsp % String name = (String)session.getAttribute("name") ; String password =
(String)session.getAttribute("password") ; %>
name : <%=name%>
password : <%=password%>
。 。 10、用户登录和兴趣选择提交显示: 、用户登录和兴趣选择提交显示:
Jsp 中 : <%@ page
contentType="text/html;charset=gbk"%> <% // 接收内容 request.setCharacterEncoding("GBK") ; String name = request.getParameter("uname") ; String inst[] = reques