struts2:
web.xml
<filter>
<!-- 配置Struts2核心Filter的名字 -->
<filter-name>struts2</filter-name>
<!-- 配置Struts2核心Filter的实现类 -->
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<!-- 配置Struts2框架默认加载的Action包结构,可以没有。 -->
<param-name>actionPackages</param-name>
<param-value>org.apache.struts2.showcase.person</param-value>
</init-param>
</filter>
<!-- 配置Filter拦截的URL -->
<filter-mapping>
<!-- 配置Struts2的核心FilterDispatcher拦截所有用户请求 -->
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<include file="struts-default.xml" />
</struts>
SPRING
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext*.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:context="http://www.springframework.org/schema/context"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:aop="http://www.springframework.org/schema/aop"
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/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.0.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/aop/spring-aop-2.5.xsd">
<bean id="datasource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/secure?useUnicode=true&characterEncoding=utf8">
</property>
<property name="username" value="root"></property>
<property name="password" value="tarena"></property>
</bean>
<bean id="messageSource"
class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
<property name="basename" value="classpath:message_zh_CN" />
</bean>
<!--
<aop:config>
<aop:pointcut expression="execution(public *com..*(..))" id="aop1"/>
<aop:aspect>
<aop:before method="" pointcut-ref=""/>
</aop:aspect>
</aop:config> -->
</beans>
SPRING SECURITY
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<b:beans xmlns="http://www.springframework.org/schema/security"
xmlns:b="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<http auto-config="true" access-denied-page="/refuse2.jsp" >
<intercept-url pattern="/index.jsp" filters="none" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<intercept-url pattern="/admin.jsp" access="ROLE_ADMIN"/>
<intercept-url pattern="/**" access="ROLE_USER,ROLE_ADMIN"/>
<session-management invalid-session-url="/timeout.jsp">
<concurrency-control max-sessions="1" error-if-maximum-exceeded="true"/>
</session-management>
<logout logout-url="/j_spring_security_logout" logout-success-url="/timeout.jsp"/>
<!-- authentication-success-handler-ref
这可以用来替换default-target-url 和always-use-default-target,你可以完全控制 成功认证之后的导航流向。这个值应该是application context中的 AuthenticationSuccessHandlerbean的名称。
authentication-failure-handler-ref
可以用来替换 authentication-failure-url, 你可以完全控制认证失败之后的导航流向。这个值应该是application context中的 AuthenticationFailureHandlerbean的名称
-->
<form-login login-page="/index.jsp" default-target-url="/success.jsp"
authentication-failure-url="/refuse.jsp"
authentication-success-handler-ref=""
authentication-failure-handler-ref=""/>
</http>
<authentication-manager>
<authentication-provider>
<!--
<password-encoder hash="md5"/>
<user-service>
<user name="admin" password="admin" authorities="ROLE_ADMIN"/>
<user name="like" password="like" authorities="ROLE_USER"/>
</user-service> -->
<jdbc-user-service data-source-ref="datasource"
authorities-by-username-query=""
users-by-username-query=""
group-authorities-by-username-query=""
/>
</authentication-provider>
</authentication-manager>
</b:beans>
MYBATIS
MYBATIS
映射文件:
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.mybatis.config.UserDao">
<select id="countAll" resultType="int">
select count(*) c from user;
</select>
<insert id="insert" parameterType="com.mybatis.config.User">
insert into user(userName,password,comment) values(#{userName},#{password},#{comment})
</insert>
<update id="update" parameterType="com.mybatis.config.User">
update user set userName=#{userName},password=#{password},comment=#{comment} where userName=#{userName}
</update>
<delete id="delete" parameterType="int">
delete from user where userName=#{userName}
</delete>
</mapper>
配置文件:his_config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<environments default="development">
<environment id="development">
<transactionManager type="JDBC" />
<dataSource type="POOLED">
<property name="driver" value="com.mysql.jdbc.Driver" />
<property name="url" value="jdbc:mysql://localhost:3306/hlp?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull" />
<property name="username" value="root" />
<property name="password" value="1234" />
</dataSource>
</environment>
</environments>
<mappers>
<mapper resource="com/mybatis/config/UserDaoMapper.xml"/>
</mappers>
</configuration>
DWR
使用步骤: 1,dwr.jar 2,web.xml 修改 ------------------------ <servlet> <servlet-name>dwr-invoker</servlet-name> <servlet-class>uk.ltd.getahead.dwr.DWRServlet</servlet-class> <init-param> <param-name>debug</param-name> <param-value>true</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>dwr-invoker</servlet-name> <url-pattern>/dwr/*</url-pattern> </servlet-mapping> --------------------------- 3,dwr.xml <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting 1.0//EN" "http://www.getahead.ltd.uk/dwr/dwr10.dtd"> --------------- <dwr> //暴露给javascript的东东 <allow> //new 是指使用默认构造器创建指定java类实例 //include 指定公开给javascript的方法 and exclude指定防止被访问的方法 //javascript指定js代码访问对象时,使用的名称 <create creator="new" javascript="testClass"> <param name="class" value="com.talkweb.declared.dao.DeclaredDao"/> <include method="testClassMethod1"/> </create> </allow> </dwr> 调用-------------- <script src="dwr/interface/testClass.js"/> <script src="dwr/engine.js"/> <script src="dwr/util.js"/> <script> //1111javascript中调用 function callTestMethod1(){ testClass.testMethod1(); } //22222调用有简单返回值的java方法 function callTestMethod2(){ testClass.testMethod2(callBackFortestMethod); } //回调的方法 **注意:data是callTestMethod2的返回值 function callBackFortestMethod(data){ alert(data); } //333333调用有简单参数的java方法; function call(){ data=""; testClass.testMethod(data); } //444444 含javaBean参数的java方法 <dwr> <allow> <create creator="new" javascript="testClass"> <include method="testMethod"/> </create> <convert converter="bean" match="com.dwr.TestBean"/> </allow> </dwr> <script> function test(){ var data={username:"",password:""}; testClass.testMethod(data); } </script> //55555调用返回List,Map参数的method <dwr> <allow> <create creator="new" javascript="testClass"> <include method="testMethod"/> </create> <convert converter="bean" match="com.dwr.TestBean"/> </allow> </dwr> <script> function test(){ testClass.testMethod(callBack); } function callBack(data){ alert(data.username); alert(data.password); } </script> //66666调用有List Map参数的java方法 <dwr> <allow> <create creator="new" javascript="testClass"> <include method="testMethod"/> </create> <convert converter="bean" match="com.dwr.TestBean"/> </allow> <signatures> <![CDATA[ import java.util.List; import com.dwr.TestClass; import com.dwr.TestBean; TestClass.testMethod7(List<TestBean>); ]]> </signatures> </dwr> </script>