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>
    

      

  • 相关阅读:
    “贴身外教”是英语口语的学习方法综合解决方案
    浅谈提高英语口语的最有效方法
    【PERL】Perl默认的内部变量
    Perl——哈希的创建和引用
    linux和windows下,C/C++开发的延时函数,sleep函数
    linux标准库#include <unistd.h>与windows的#include <windows.h>(C语言开发)
    linux 如何显示一个文件的某几行(中间几行)
    使程序在Linux下后台运行
    Perl中关于数组的输出——需要注意的地方
    linux下C/C++,多线程pthread
  • 原文地址:https://www.cnblogs.com/linlf03/p/7637575.html
Copyright © 2011-2022 走看看