jsp中的一些页面的语法的讲解和连接的讲解

来源:互联网 发布:linux json 格式化 编辑:程序博客网 时间:2024/06/06 04:46

Servlet
JSP
  java server page
  jsp-->servlet-->html

组成
 
   <%
      java脚本,生成在service中
   %>

   <%=
      表达式,千万不能写;生成servvice方法中
 
   %>


   指令
   <%@page import=""   %>
   <%@include file=""  %>
   <%@taglib  prefix="" uri="" %>

   注释
   <!-- 在客户端源代码中可以看到 -->
   <%-- 看不到 --%>

   声明
   <%!
  
      int x; //定义变量,定义方法,生成的代码是在service外,生成的变量是一个全局变量
   %>

 

连接池:
     事先创建好很多连接,放在一个集合中,以后要用从中取出来。

     空闲连接数(初始连接数) :10
     最大连接数:20
    
     
     连接池实现:
            web容器
     第三方开发包

import java.sql.Connection;
import java.sql.SQLException;

import org.apache.commons.dbcp.BasicDataSource;

public class DbUtil {
 static BasicDataSource dataSource = new BasicDataSource();
 
 static {
  dataSource.setUsername("sa");
  dataSource.setPassword("sasa");
  dataSource
    .setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
  dataSource.setUrl("jdbc:sqlserver://127.0.0.1:1433;DatabaseName=student");
  dataSource.setMaxIdle(20);
  dataSource.setMinIdle(10);
 }

 public static Connection getCon() {

  try {
   return dataSource.getConnection();
  } catch (SQLException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
  return null;
 }
 
 public static void main(String[] args) throws SQLException {
        Connection  con = getCon();
        System.out.println(con.getCatalog());
 }

}

 

原创粉丝点击