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
struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/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);
/*
*/
var userName = $(".userName");
var password = $(".password");
var tip = "";
if( $.trim( userName.val() ) == "" ){
tip = "帐号不能为空";
userName.focus();
}else if( !/^\w{5,20}$/.test( userName.val() ) ){
tip = "帐号长度必须5-20之间";
userName.focus();
}else if($.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";
}else if(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
package org.dawen.action.admin;
import org.dawen.action.base.AbstractAjaxAction;
/**
* 异步登录Ajax,接收用户名和密码参数
* @author jun
* @email 624664181@qq.com
* @date 2014 下午8:47:07
*/
public class LoginAjaxAction extends AbstractAjaxAction {
private static final long serialVersionUID = -1638526442566751841L;
protected String userName;
protected String password;
@Override
public String setJson() throws Exception {
String json = this.service.login(userName,password);
return json;
}
/** getter and setter method */
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
this.userName = userName;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
}
LoginInterceptor.java
package org.dawen.action.interceptor;
import org.dawen.commons.WebConstant;
import org.dawen.dto.User;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
/**
* 自定义登录拦截器类继承struts2框架提供的拦截器类AbstractInterceptor,AbstractInterceptor类实现了Interceptor接口
* 接口Interceptor的默认方法有:init()、intercept(ActionInvocation arg0)、destroy()
* AbstractInterceptor有Interceptor的三个方法,不需要加载特殊资源时可以不用实现init()和destroy()方法,只需实现intercept(ActionInvocation invocation)
* @author jun
* @email 624664181@qq.com
* @date 2014 下午8:28:59
*/
public class LoginInterceptor extends AbstractInterceptor{
private static final long serialVersionUID = 6706022458603193697L;
/**
* 实现用户拦截的处理方法。类似action的execute()方法,返回String类型的结果来对应配置文件中的视图名。
* 如果该方法直接返回一个字符串,则框架跳转到该字符串对应的逻辑视图
*/
public String intercept(ActionInvocation invocation) throws Exception {
System.out.println("LoginInterceptor...interceptor.....");
//从session获取当前用户User对象
User user = (User) invocation.getInvocationContext().getSession().get(WebConstant.SESSION_USER);
if(user != null){
//调用被拦截的action
return invocation.invoke();
}
//不成功则直接返回一个字符串
return WebConstant.USER_LOGIN;
}
}
DBConnection.java
package org.dawen.dao.base;
import java.sql.Connection;
import java.sql.SQLException;
import com.mchange.v2.c3p0.ComboPooledDataSource;
/**
* 数据库连接类
* @author jun
* @email 624664181@qq.com
* @date 2014 下午4:52:30
*/
public class DBConnection {
//定义c3p0连接池
private static ComboPooledDataSource db = new ComboPooledDataSource();
/**
* 获取数据源连接
* @return
* @throws SQLException
*/
public static Connection getConnection() throws SQLException{
return db.getConnection();
}
/**
* 关闭数据源
* @param connection
* @throws SQLException
*/
public static void close(Connection connection) throws SQLException{
if(connection != null){
connection.close();
}
}
}