栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

JSP中的数据访问

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

JSP中的数据访问

了解这五点:

1、include指令

2、application内置对象

3、JSP对象的作用域

3.1page作用域

 

3.2request作用域

 

3.3session作用域

3.4application作用域

 

示例代码:

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="one.jsp"%>

  
    引入
  
  
  <%="Hello World!"%>
  
欢迎进入网站 <% //page作用域:当前页面 pageContext.setAttribute("pc","page"); //request作用域:一次请求 request.setAttribute("req","request"); //session作用域:一次会话 session.setAttribute("sess","session"); //application作用域:当前应用程序 application.setAttribute("app","application"); request.getRequestDispatcher("two.jsp").forward(request,response); %> page作用域中的值:<%=pageContext.getAttribute("pc")%>

 

<%@ page contentType="text/html;charset=UTF-8" language="java" %>



    页面


    <%
        //获取count的值
        Integer count=(Integer) application.getAttribute("count");
        if(count!=null){//不是第一次访问
            count+=1;
        }else{//第一次访问
            count=1;
        }
        application.setAttribute("count",count);
    %>
    该网站被访问<%=(Integer) application.getAttribute("count")%>


<%@ page contentType="text/html;charset=UTF-8" language="java" %>


    Title


    
        page作用域中的值:<%=pageContext.getAttribute("pc")%>
    
    
        request作用域中的值:<%=request.getAttribute("req")%>
    
    
        session作用域中的值:<%=session.getAttribute("sess")%>
    
    
        application作用域中的值:<%=application.getAttribute("app")%>
    

运行效果:

 

4、使用JDBC链接数据库

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/872411.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号