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

8 篇文章 0 订阅

博主采用的是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包。


  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值