常见的配置文件的头文件

beans.xml

<?xml version="1.0"encoding="UTF-8"?>

<beansxmlns="http://www.springframework.org/schema/beans"

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xmlns:context="http://www.springframework.org/schema/context"

         xmlns:aop="http://www.springframework.org/schema/aop"

         xmlns:tx="http://www.springframework.org/schema/tx"

         xsi:schemaLocation="http://www.springframework.org/schema/beans

                                             http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

                                              http://www.springframework.org/schema/context

                                             http://www.springframework.org/schema/context/spring-context-3.0.xsd

                                             http://www.springframework.org/schema/tx

                                             http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

                                             http://www.springframework.org/schema/aop

                                              http://www.springframework.org/schema/aop/spring-aop-3.0.xsd">

</beans>


jdbc.properties

jdbc.driverclass=com.mysql.jdbc.Driver

jdbc.url=jdbc:mysql://localhost:3306/mybatisdb?characterEncoding=UTF-8

jdbc.username=root

jdbc.password=root

 

c3p0.pool.size.max=10

c3p0.pool.size.min=2

c3p0.pool.size.ini=3

c3p0.pool.size.increment=2

 

 

log4j.properties

log4j.rootLogger=INFO, Console

#Console

log4j.appender.Console=org.apache.log4j.ConsoleAppender

log4j.appender.Console.layout=org.apache.log4j.PatternLayout

log4j.appender.Console.layout.ConversionPattern=%d[%t] %-5p [%c] - %m%n

log4j.logger.java.sql.ResultSet=INFO

log4j.logger.org.apache=INFO

log4j.logger.java.sql.Connection=DEBUG

log4j.logger.java.sql.Statement=DEBUG

log4j.logger.java.sql.PreparedStatement=DEBUG

 

springmvc-servlet.xml

<?xml version="1.0"encoding="UTF-8"?>

<beansxmlns="http://www.springframework.org/schema/beans"

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xmlns:mvc="http://www.springframework.org/schema/mvc"

         xmlns:context="http://www.springframework.org/schema/context"

         xmlns:aop="http://www.springframework.org/schema/aop"

         xmlns:tx="http://www.springframework.org/schema/tx"

         xsi:schemaLocation="http://www.springframework.org/schema/beans

         http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

         http://www.springframework.org/schema/mvc

         http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd

         http://www.springframework.org/schema/context

         http://www.springframework.org/schema/context/spring-context-3.0.xsd

         http://www.springframework.org/schema/aop

         http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

         http://www.springframework.org/schema/tx

         http://www.springframework.org/schema/tx/spring-tx-3.0.xsd">

        

         <!--1.包扫描 -->

         <context:component-scanbase-package="cn.itcast.mybatis.controller"/>

        

         <!--2.内部资源视图解析器规则:前缀+逻辑名+后缀  /WEB-INF/pages/user/jUserList.jsp-->

         <beanid="jspViewResolver"class="org.springframework.web.servlet.view.InternalResourceViewResolver">

                   <propertyname="prefix" value="/WEB-INF/pages"/>

                   <propertyname="suffix" value=""/>

         </bean>

</beans>

 

 

 

 

 

sqlMapConfig.xml

<?xml version="1.0"encoding="UTF-8" ?>

<!DOCTYPE configuration

PUBLIC "-//mybatis.org//DTD Config3.0//EN"

"http://mybatis.org/dtd/mybatis-3-config.dtd">

<configuration>

</configuration>

 

struts.xml

<?xml version="1.0"encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC

    "-//Apache Software Foundation//DTD Struts Configuration2.1.7//EN"

    "http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>

    <constant name="struts.ui.theme"value="simple"></constant>

    <constant name="struts.devMode"value="true"></constant>

    <constant name="struts.objectFactory"value="spring"></constant>

    

    <package name="user" namespace="/user"extends="struts-default">

         <action name="userAction_*"class="cn.itcast.mybatis.action.UserAction"method="{1}">

              <resultname="pview">/WEB-INF/jsps/user/jUserView.jsp</result>

               <resultname="plist">/WEB-INF/jsps/user/jUserList.jsp</result>

               <resultname="pcreate">/WEB-INF/jsps/user/jUserCreate.jsp</result>

               <result name="pupdate">/WEB-INF/jsps/user/jUserUpdate.jsp</result>

               <resultname="actlist"type="redirectAction">/user/userAction_list</result>

         </action>

    </package>

</struts>

 

 

 

 

Struts2-web.xml

<?xml version="1.0"encoding="UTF-8"?>

<web-app version="2.4"xmlns="http://java.sun.com/xml/ns/j2ee"

         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee

         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

 

         <context-param>

                   <param-name>contextConfigLocation</param-name>

                   <param-value>classpath:beans.xml</param-value>

         </context-param>

         <listener>

                   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

         </listener>

 

         <filter>

                   <filter-name>struts2</filter-name>

                   <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>

         </filter>

         <filter-mapping>

                   <filter-name>struts2</filter-name>

                   <url-pattern>/*</url-pattern>

         </filter-mapping>

 

         <welcome-file-list>

                   <welcome-file>index.jsp</welcome-file>

         </welcome-file-list>

</web-app>

 

 

 

TestJdbc.java

package test;

 

import java.sql.Connection;

import java.sql.DriverManager;

import java.sql.PreparedStatement;

import java.sql.ResultSet;

import java.sql.SQLException;

 

/**

 * 从一个jdbc程序找出存在的问题

 *

 *@author 传智播客 Java学院陈子枢

 *@version V1.0

 */

public class TestJdbc {

         publicstatic void main(String[] args) {

 

                   Connectionconnection = null;

                   PreparedStatementpreparedStatement = null;

                   ResultSetresultSet = null;

 

                   try{

                            //加载数据库驱动

                            Class.forName("com.mysql.jdbc.Driver");

 

                            //通过驱动管理类获取数据库链接

                            connection= DriverManager

                                               .getConnection(

                                                                 "jdbc:mysql://localhost:3306/mybatis?characterEncoding=utf-8",

                                                                 "root","mysql");

                            //定义sql语句 ?表示占位符

                            Stringsql = "select id,username from user where username = ?";

                            //获取预处理statement

                            preparedStatement= connection.prepareStatement(sql);

                            //设置参数,第一个参数为sql语句中参数的序号(从1开始),第二个参数为设置的参数值

                            preparedStatement.setString(1,"张三");

                            //向数据库发出sql执行查询,查询出结果集

                            resultSet= preparedStatement.executeQuery();

                            //遍历查询结果集

                            while(resultSet.next()) {

                                     System.out.println(resultSet.getString("id")+ "  "

                                                        +resultSet.getString("username"));

                            }

                   }catch (Exception e) {

                            e.printStackTrace();

                   }finally {

                            //释放资源

                            if(resultSet != null) {

                                     try{

                                               resultSet.close();

                                     }catch (SQLException e) {

                                               //TODO Auto-generated catch block

                                               e.printStackTrace();

                                     }

                            }

                            if(preparedStatement != null) {

                                     try{

                                               preparedStatement.close();

                                     }catch (SQLException e) {

                                               //TODO Auto-generated catch block

                                               e.printStackTrace();

                                     }

                            }

                            if(connection != null) {

                                     try{

                                               connection.close();

                                     }catch (SQLException e) {

                                               //TODO Auto-generated catch block

                                               e.printStackTrace();

                                     }

                            }

 

                   }

 

         }

}

 

 

 

 

web.xml

<?xml version="1.0"encoding="UTF-8"?>

<web-appxmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                   xmlns="http://java.sun.com/xml/ns/javaee"

                   xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"

                   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee

                   http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"

                 id="WebApp_ID"version="3.0">

 

         <!--1.spring侦听 -->

         <context-param>

                   <param-name>contextConfigLocation</param-name>

                   <param-value>classpath:beans.xml</param-value>

         </context-param>

         <listener>

                   <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

         </listener>

        

         <!--2.springmvc DispatcherServlet  -->

         <servlet>

                   <servlet-name>springmvc</servlet-name>

                   <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

                   <init-param>

                            <param-name>contextConfigLocation</param-name>

                            <param-value>classpath:springmvc-servlet.xml</param-value>

                   </init-param>

         </servlet>

         <servlet-mapping>

                   <servlet-name>springmvc</servlet-name>

                   <url-pattern>/</url-pattern>

         </servlet-mapping>

        

        

         <!--3.中文乱码 filter -->

         <!--编码过滤器,解决中文乱码 -->

         <filter>

                   <filter-name>SpringEncoding</filter-name>

                   <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>

                   <init-param>

                            <param-name>encoding</param-name>

                            <param-value>utf-8</param-value>

                   </init-param>

         </filter>

         <filter-mapping>

                   <filter-name>SpringEncoding</filter-name>

                   <url-pattern>/*</url-pattern>

         </filter-mapping>

</web-app>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值