1.项目名:微信公众号后台管理系统
2.开发工具:eclipse+tomcat7.0
3.所用技术:jdbc+struts2
4.实现的主要功能:消息自动回复,自定义图文素材和文本素材,自定义公众号菜单,微信群管理功能。
5.项目访问地址:
项目结构:
部分代码 :
web.xml:
404
/404.jsp
index.jsp
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*
33
*.jsp
false
true
/WEB-INF/jsp/taglib.jsp
struts.xml
strutsPUBLIC
"-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.3//EN"
"/dtds/struts-2.3.dtd">
/error.jsp
/WEB-INF/jsp/admin/login.jsp
/WEB-INF/jsp/admin/{1}.jsp
c3p0.properties
c3p0.driverClass=com.mysql.jdbc.Driver
c3p0.jdbcUrl=jdbc:mysql://localhost:3306/dawen
c3p0.user=root
c3p0.password=a123
c3p0.initialPoolSize=2
c3p0.maxIdleTime=30
c3p0.maxPoolSize=100
c3p0.minPoolSize=10
login.jsp
pageEncoding="UTF-8"%>
HTML>
微信公众号管理后台登录
$(function(){
$("#btn").click(function(){
var$_login=$("#loginForm").get(0);
var$_tip=$("#tip").get(0);
/*
*/
varuserName=$(".userName");
varpassword=$(".password");
vartip="";
if($.trim(userName.val())==""){
tip="帐号不能为空";
userName.focus();
}elseif(!/^\w{5,20}$/.test(userName.val())){
tip="帐号长度必须5-20之间";
userName.focus();
}elseif($.trim(password.val())==""){
tip="密码不能为空";
password.focus();
}
if(tip!=""){//如果tip有值提示错误信息
alert(tip);
}else{//发送ajax请求
$.ajax({
url:"${pageContext.request.contextPath}/loginAjax.action",//ajax的请求地址
type:"post",//请求方式
dataType:"json",//返回数据为json
data:$("#form").serialize(),//$("#loginForm").serialize()序列化
async:true,//是否异步true为异步,false为同步
success:function(data){//异步成功回调
console.log(data);
if(data.success=="1"){
alert(data.tip);
//Dialog.alert("登录成功~~!");
window.location="${pageContext.request.contextPath}/index.action";
}elseif(data.success=="0"){
antMove($_login,{top:60},1000,"elasticOut",function(){
$(".tip").css("display","block");
antMove($_tip,{top:0},1000,"elasticOut");});
}
},
error:function(tip){//ajax失败回调
alert("ajax发送失败:"+tip);
}
});
}
});
});
错误:
用户名无效
忘记密码?
用户名
密码
记住我的登录信息
LoginAjaxAction.java
packageorg.dawen.action.admin;
importorg.dawen.action.base.AbstractAjaxAction;
/**
*异步登录Ajax,接收用户名和密码参数
*@authorjun
*@email624664181@
*@date下午8:47:07
*/
publicclassLoginAjaxActionextendsAbstractAjaxAction{
privatestaticfinallongserialVersionUID=-1638526442566751841L;
protectedStringuserName;
protectedStringpassword;
@Override
publicStringsetJson()throwsException{
Stringjson=this.service.login(userName,password);
returnjson;
}
/**getterandsettermethod*/
publicStringgetUserName(){
returnuserName;
}
publicvoidsetUserName(StringuserName){
this.userName=userName;
}
publicStringgetPassword(){
returnpassword;
}
publicvoidsetPassword(Stringpassword){
this.password=password;
}
}
LoginInterceptor.java
packageorg.dawen.action.interceptor;
mons.WebConstant;
importorg.dawen.dto.User;
importcom.opensymphony.xwork2.ActionInvocation;
importcom.opensymphony.xwork2.interceptor.AbstractInterceptor;
/**
*自定义登录拦截器类继承struts2框架提供的拦截器类AbstractInterceptor,AbstractInterceptor类实现了Interceptor接口
*接口Interceptor的默认方法有:init()、intercept(ActionInvocationarg0)、destroy()
*AbstractInterceptor有Interceptor的三个方法,不需要加载特殊资源时可以不用实现init()和destroy()方法,只需实现intercept(ActionInvocationinvocation)
*@authorjun
*@email624664181@
*@date下午8:28:59
*/
publicclassLoginInterceptorextendsAbstractInterceptor{
privatestaticfinallongserialVersionUID=6706022458603193697L;
/**
*实现用户拦截的处理方法。类似action的execute()方法,返回String类型的结果来对应配置文件中的视图名。
*如果该方法直接返回一个字符串,则框架跳转到该字符串对应的逻辑视图
*/
publicStringintercept(ActionInvocationinvocation)throwsException{
System.out.println("LoginInterceptor...interceptor.....");
//从session获取当前用户User对象
Useruser=(User)invocation.getInvocationContext().getSession().get(WebConstant.SESSION_USER);
if(user!=null){
//调用被拦截的action
returninvocation.invoke();
}
//不成功则直接返回一个字符串
returnWebConstant.USER_LOGIN;
}
}
DBConnection.java
packageorg.dawen.dao.base;
importjava.sql.Connection;
importjava.sql.SQLException;
importcom.mchange.boPooledDataSource;
/**
*数据库连接类
*@authorjun
*@email624664181@
*@date下午4:52:30
*/
publicclassDBConnection{
//定义c3p0连接池
privatestaticComboPooledDataSourcedb=newComboPooledDataSource();
/**
*获取数据源连接
*@return
*@throwsSQLException
*/
publicstaticConnectiongetConnection()throwsSQLException{
returndb.getConnection();
}
/**
*关闭数据源
*@paramconnection
*@throwsSQLException
*/
publicstaticvoidclose(Connectionconnection)throwsSQLException{
if(connection!=null){
connection.close();
}
}
}