zoukankan      html  css  js  c++  java
  • JSP 内置对象

    1. JSP的内置对象有

    request,请求对象,代表来自客户端的请求

    response, 响应对象,代表对客户端的响应

    out,输出对象,通过out对象发送的内容将是浏览器需要显示的内容。

    application 应用程序对象,负责提供应用程序在服务器中运行时提供的一些全局信息。

    config 配置对象

    page 页面对象

    exception 异常对象

    pageContext 页面上下午对象

    session 会画对象, 代表服务器与客户端所建立的会话,当需要保存在不同的JSP页面中保留客户信息的情况下使用,比如在线购物、客户轨迹跟踪等。

    2. request,out对象的使用

    创建login.jsp, result.jsp

    login.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <form action="result.jsp" method="post">
    	username: <input type="text" name="username1"><br>
    	password: <input type="password" name="password1"><br>
    	
    	<input type="submit" value="submit" >    
    	<input type="reset" value="reset" >
    </form>
    </body>
    </html>
    

      result.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <%
    	String username = request.getParameter("username1");
    	String password = request.getParameter("password1");
    	out.println("username:" + username + "<br>");
    	out.println("password:" + password + "<br>");
    	System.out.println("username:" + username );
    	System.out.println("password:" + password );
    %>
    </body>
    </html>
    

      result.jsp 使用了request和out对象。

    3. session对象的使用

    session1.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    	<form action="session2.jsp">
    		姓名
    		<input type="text" name="username">
    		<input type="submit" value="提交">
    	</form>
    </body>
    </html>
    

     

    session2.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <%
    	String username = request.getParameter("username");
    	session.setAttribute("LogName", username);
    
    %>
    你的名字是 <%=username %>已經写入session
    <br>
    <a href='session3.jsp'>check</a>
    </body>
    </html>
    

      

    session3.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    session值为:
    <% String yourname = (String)session.getAttribute("LogName");
    	if(yourname == null) {
    %>
    您还未登录
    <% } else { %>
    "<%=yourname %>"已经登录
    <%} %>
    </body>
    </html>
    

      

  • 相关阅读:
    轻量级的Web服务器Nginx0.9.0 开发版发布 狼人:
    微软发布Silverlight 5 Beta新特性 狼人:
    TechCrunch新闻评论:Flash耗电问题严重 狼人:
    IE9是最佳浏览器? 狼人:
    Silverlight面向客户端,HTML5面向Web 狼人:
    Silverlight 结构分析 狼人:
    HTML5是否已经准备好了?仍在W3C层层审核当中 狼人:
    Adobe驳斥Flash过度耗电论 称HTML5更耗电 狼人:
    Silverlight 5即将来临 狼人:
    运行控制[置顶] 有趣的编程控制自己电脑的CPU
  • 原文地址:https://www.cnblogs.com/linlf03/p/7637575.html
Copyright © 2011-2022 走看看