您的位置:首页 > 移动开发 > 微信开发

java微信网页授权获取用户信息以及JSSDK自定义分享等功能<一>

2015-12-07 14:18 1461 查看
博主采用的是eclipse+springmvc+jsp来做这一功能讲解。如控制器采用的是其他组件,原理一样,自己结合自己的实际环境来调整。

尊重原创,觉得有用多多推广,顺便给个赞。谢谢。

分三步:

第一,web.xml和applicationContext.xml的配置,如已掌握的童鞋,可自动忽略这节。

新建一个web工程,然后在src目录下新建一个applicationContext.xml文件

web.xm文件,源码在图片下方



<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> 
<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:applicationContext.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springmvc</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

<filter>
<filter-name>encodingfilter</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>encodingfilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<welcome-file-list>
<welcome-file>/WEB-INF/index.jsp</welcome-file>
</welcome-file-list>

<error-page>
<error-code>404</error-code>
<location>/WEB-INF/404.jsp</location>
</error-page>

</web-app>


applicationContext.xml文件



<?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:context="http://www.springframework.org/schema/context" xmlns:util="http://www.springframework.org/schema/util"
xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:jpa="http://www.springframework.org/schema/data/jpa" xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa-1.3.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

<mvc:interceptors>
<mvc:interceptor>
<!--定义拦截哪些请求  -->
<mvc:mapping path="/*"/>
<!-- 定义不拦截器哪些请求 -->
<mvc:exclude-mapping path="/lvyouju/lvyou.do"/>
<mvc:exclude-mapping path="/lvyouju/*"/>
<mvc:exclude-mapping path="/ruidian/*"/>
<mvc:exclude-mapping path="/geermo/*"/>
<mvc:exclude-mapping path="/goldenbo/*"/>
<mvc:exclude-mapping path="/scona/*"/>
<bean class="org.lvyouju.web.interceptor.CheckInterceptor"/>
</mvc:interceptor>
</mvc:interceptors>
<context:component-scan base-package="org.lvyouju"/>

<bean id="dbcpdatasource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="username" value="root">
</property>
<property name="password" value="123456">
</property>
<property name="driverClassName" value="com.mysql.jdbc.Driver">
</property>
<property name="url" value="jdbc:mysql:///lvyouju">
</property>
</bean>

<mvc:annotation-driven/>

<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/">
</property>
<property name="suffix" value=".jsp">
</property>
</bean>

</beans>


整个工程目录如下:



项目引入jar包如下:这些是工程中用到的全部jar包,包括加解密,xml解析,springmvc等用到的全部jar包。如你的工程不需要则可以自行删除对应jar包。

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: