基于struts环境下的jquery easyui环境搭建
下载地址:
http://download.csdn.net/detail/cyberzhaohy/7348451
加入了json包:jackson-all-1.8.5.jar,项目结构例如以下:
測试网址:
http://localhost:9090/jquery-easyui-1.2.6BasedonStruts/layout.jsp
效果图例如以下:
配置文件web.xml:
<?xml
version="1.0"
encoding="UTF-8"?>
<web-app
version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:beans.xml</param-value>
</context-param>
<filter>
<filter-name>openSessionInView</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
<init-param>
<param-name>sessionFactoryBeanName</param-name>
<param-value>sf</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>openSessionInView</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
beans.xml配置,上面配置文件黄色代码sf使用以下黄色代码配置:
<?
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:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
<context:annotation-config/>
<context:component-scanbase-package="com.xdy"></context:component-scan>
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property
name="locations">
<value>classpath:jdbc.properties</value>
</property>
</bean>
<bean
id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource"
destroy-method="close">
<property
name="driverClassName"
value="${jdbc.driverClassName}"/>
<property
name="url"
value="${jdbc.url}"/>
<property
name="username"
value="${jdbc.username}"
/>
<property
name="password"
value="${jdbc.password}"
/>
</bean>
<bean
id="sf"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property
name="dataSource"ref="dataSource"/>
<property
name="packagesToScan">
<list>
<value>com.xdy.registration.model</value>
</list>
</property>
<property
name="hibernateProperties">
<props>
<prop
key="hibernate.dialect">
org.hibernate.dialect.OracleDialect
</prop>
<prop
key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
<bean
id="hibernateTemplate"
class="org.springframework.orm.hibernate3.HibernateTemplate">
<property
name="sessionFactory"
ref="sf"></property>
</bean>
<bean
id="txManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property
name="sessionFactory"
ref="sf"></property>
</bean>
<aop:config>
<aop:pointcut
id="bussinessService"
expression="execution(public* com.xdy.registration.service.*.*(..))"></aop:pointcut>
<aop:advisor
pointcut-ref="bussinessService"
advice-ref="txAdvice"/>
</aop:config>
<tx:advice
id="txAdvice"
transaction-manager="txManager">
<tx:attributes>
<tx:method
name="exists"read-only="true"
/>
<tx:method
name="add*"
propagation="REQUIRED"
/>
</tx:attributes>
</tx:advice>
</beans>
控制逻辑struts.xml配置:
<!DOCTYPE
struts PUBLIC
"-//Apache Software Foundation//DTDStruts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant
name="struts.i18n.encoding"
value="GBK"/>
<package
name="registration"
extends="struts-default">
<action
name="u"
class="com.xdy.registration.action.UserAction">
<result
name="success">/registerSuccess.jsp</result>
<result
name="fail">/registerFail.jsp</result>
<result
name="list">/UserList.jsp</result>
<result
name="load">/User.jsp</result>
</action>
</package>
</struts>
UserAction.java代码例如以下:
package com.xdy.registration.action;
import java.io.IOException;
import java.io.StringWriter;
import java.util.List;
import org.apache.struts2.ServletActionContext;
import org.codehaus.jackson.JsonFactory;
import org.codehaus.jackson.JsonGenerator;
import org.codehaus.jackson.map.ObjectMapper;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.xdy.registration.model.MyUser;
import com.xdy.registration.service.UserManager;
import com.xdy.registration.vo.UserRegisterInfo;
//@Component("user")
//@Component("u")
//@Scope("prototype")
publicclass UserAction
extends ActionSupport
implements ModelDriven {
public Object getModel() {
//
TODO Auto-generatedmethod stub
returninfo;
}
/*
* private Stringusername;; private String password; private String
* password2;
*
* public StringgetUsername() { return username; }
*
* public voidsetUsername(String username) { this.username = username; }
*
* public StringgetPassword() { return password; }
*
* public voidsetPassword(String password) { this.password = password; }
*
* public StringgetPassword2() { return password2; }
*
* public voidsetPassword2(String password2) { this.password2 = password2; }
*/
private UserRegisterInfo
info =
new UserRegisterInfo();
private UserManager
userManager;
private List<MyUser>
users;
private MyUser
myUser;
public MyUser getMyUser() {
returnmyUser;
}
publicvoid setMyUser(MyUser myUser) {
this.myUser = myUser;
}
public String list() {
this.users =
this.userManager.getUsers();
return"list";
}
public List<MyUser> getUsers() {
returnusers;
}
publicvoid setUsers(List<MyUser> users) {
this.users = users;
}
public UserAction() {
System.out.println("useractioncreated!");
}
/*
* public UserAction() {ApplicationContext ctx = new
*ClassPathXmlApplicationContext("beans.xml"); um = (UserManager)
*ctx.getBean("userManager"); }
*/
@Override
public String execute()
throws Exception {
System.out.println(info.getUsername());
/*
* if (password !=password2) { return "fail"; }
*/
MyUser u = new MyUser();
u.setUsername(info.getUsername());//username);
u.setPassword(info.getPassword());//password);
if (userManager.exists(u)) {
return"fail";
}
userManager.add(u);
return"success";
}
publicvoid datagird() {
list();
writeJson(this.users);
}
publicvoid writeJson(Object o) {
String json=getJsonString(o);
try{
ServletActionContext.getResponse().getWriter().write(json);
}catch(IOException e){
e.printStackTrace();
}
}
public String getJsonString(Object o) {
ObjectMapper om=new ObjectMapper();
StringWriter sw=new StringWriter();
try{
JsonGenerator jg=new JsonFactory().createJsonGenerator(sw);
om.writeValue(jg, o);
jg.close();
}
catch(IOException e){
e.printStackTrace();
}
return sw.toString();
}
public UserManager getUserManager() {
returnuserManager;
}
publicvoid setUserManager(UserManager userManager) {
this.userManager = userManager;
}
public UserRegisterInfo getInfo() {
returninfo;
}
publicvoid setInfo(UserRegisterInfo info) {
this.info = info;
}
public String load() {
this.myUser =
this.userManager.loadById(info.getId());
return"load";
}
}
界面调用layout.jsp代码:
<%@ page
language="java"
import="java.util.*"
pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() +
"://"
+ request.getServerName() +
":" + request.getServerPort()
+ path +
"/";
%>
<!DOCTYPE
HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base
href="<%=basePath%>">
<title>My JSP'layout.jsp' starting page</title>
<meta
http-equiv="pragma"
content="no-cache">
<meta
http-equiv="cache-control"
content="no-cache">
<meta
http-equiv="expires"
content="0">
<meta
http-equiv="keywords"
content="keyword1,keyword2,keyword3">
<meta
http-equiv="description"
content="This is my page">
<!--
<link rel="stylesheet" type="text/css"href="styles.css">
-->
<script
type="text/javascript"
src="js/jquery-1.7.2.min.js"
charset="UTF-8"></script>
<script
type="text/javascript"
src="js/jquery.easyui.min.js"
charset="UTF-8"></script>
<link
rel="stylesheet"
href="js/themes/default/easyui.css"
type="text/css"></link>
<link
rel="stylesheet"
href="js/themes/icon.css"
type="text/css"></link>
<script
type="text/javascript"
src="js/locale/easyui-lang-zh_CN.js"
charset="UTF-8"></script>
<script
charset="UTF-8">
var
cc;
$(function(){
cc = $('#cc').layout();
cc.layout('collapse','west');
});
function
getCenterPanel(){
var
centerPanel=$('#cc').layout('panel','center');
console.info(centerPanel.panel('options').title);
}
</script>
</head>
<body
id="cc">
<div
region="north"
title="NorthTitle"
style="height:100px;">
<input
type="button"value="展开西部面板"
onclick="cc.layout('expand','west');"/>
</div>
<div
region="south"
title="southTitle"
split="true"
style="height:100px;">
<input
type="button"value="获得center面板"
onclick="getCenterPanel();"/>
</div>
<div
region="west"
title="westTitle"
split="true"
collapse="true"
style="width:200px;"></div>
<div
region="center"
iconCls="icon-save"href="center.html"title="centerTitle"
style="overflow:hidden;">
</div>
</body>
</html>
被引入代码center.html例如以下:
<script
type="text/javascript"
charset="utf-8">
var
datagrid;
$(function(){
$('#datagrid').datagrid({
//url:sy.bp()+'/userAction!datagrid',
url:'u!datagird.action',
title:'ddddd',
iconCls:'icon-save',
pagination:true,
pageSize:10,
pageList:[10,20,30,40],
fit:true,
fitColumns:false,
nowarp:false,
border:false,
idField:'id',
columns:[[{
title:'编号',
field:'id',
width:100
},{
title:'姓名',
field:'name',
width:100
},{
title:'password',
field:'password',
width:100
}]]
});
});
</script>
<div
class="easyui-tabs"
fit="true"
border="false">
<div
title="user management管理"
border="false">
<table
id="datagrid"></table>
</div>
</div>
基于struts环境下的jquery easyui环境搭建的更多相关文章
- Centos7环境下etcd集群的搭建
Centos7环境下etcd集群的搭建 一.简介 "A highly-available key value store for shared configuration and servi ...
- 01.1 Windows环境下JDK安装与环境变量配置详细的图文教程
01.1 Windows环境下JDK安装与环境变量配置详细的图文教程 本节内容:JDK安装与环境变量配置 以下是详细步骤 一.准备工具: 1.JDK JDK 可以到官网下载 http://www.or ...
- Linux环境下SolrCloud集群环境搭建关键步骤
Linux环境下SolrCloud集群环境搭建关键步骤. 前提条件:已经完成ZooKeeper集群环境搭建. 一.下载介质 官网下载地址:http://www.apache.org/dyn/close ...
- Linux环境下HDFS集群环境搭建关键步骤
Linux环境下HDFS集群环境搭建关键步骤记录. 介质版本:hadoop-2.7.3.tar.gz 节点数量:3节点. 一.下载安装介质 官网下载地址:http://hadoop.apache.or ...
- Linux环境下ZooKeeper集群环境搭建关键步骤
ZooKeeper版本:zookeeper-3.4.9 ZooKeeper节点:3个节点 以下为Linux环境下ZooKeeper集群环境搭建关键步骤: 前提条件:已完成在Linux环境中安装JDK并 ...
- virtualenv 环境下 Nginx + Flask + Gunicorn+ Supervisor 搭建 Python Web
在这篇文章里,我们将搭建一个简单的 Web 应用,在虚拟环境中基于 Flask 框架,用 Gunicorn 做 wsgi 容器,用 Supervisor 管理进程,然后使用 Python 探针来监测应 ...
- windows环境下简单Jenkins持续集成搭建
Jenkins是基于Java开发的持续集成工具,所以在安装Jenkins之前我们要确定电脑上已经安装了Java JDK并且环境变量配置正确,否则在启动使用java -jar Jenkins.war启动 ...
- Windows环境下,python webdriver环境搭建
最近刚开始学习selenium,这是我从虫师的<selenium2自动测试实战--基于Python语言>这本书上学到搭建环境的步骤,里面有加上我的一些总结,希望对大家有所帮助! 准备工 ...
- Windows环境下ARM集成开发环境的搭建与使用
Windows环境下能够使用Eclipse IDE for C/C++ Developers来搭建ARM开发环境 本文地址:http://blog.csdn.net/u011833609/articl ...
随机推荐
- C第12章-----堆
#include <stdio.h> #include <stdlib.h> //声明Person结构 //struct Person{ // float heightI ...
- 【01】恶趣味玩转 GitHub commit 历史记录
[黑科技]恶趣味玩转 GitHub commit 历史记录 工具:https://github.com/gelstudios/gitfiti 效果截图:预览地址:https://github.co ...
- mq推送消息
场景:BDM(实名制系统)同步数据到CRNS(实名制系统) 一,首先建个队列,队列名字为 bdm_empolyeeinfo_crns 二,applicationContext-rabbitmq.xml ...
- 78. Spring Boot完美使用FastJson解析JSON数据【从零开始学Spring Boot】
[原创文章,转载请注明出处] 个人使用比较习惯的json框架是fastjson,所以spring boot默认的json使用起来就很陌生了,所以很自然我就想我能不能使用fastjson进行json解析 ...
- HDU-2647 Reward ,逆拓排。
Reward 发工资,以前看过这题,做没做忘了(应该是没做). 很明显的拓排.但数据范围这么大,吓得我当时就不敢动手.后来找题解发现还是相当于两层循环(are you kidding me?)当时卡在 ...
- [luoguP2982][USACO10FEB]慢下来Slowing down(dfs序 + 线段树)
传送门 这个题显然可以用树链剖分做. 然而线段树也能做. 每个点都对它的子树有贡献,所以先求一边 dfs序,然后直接在 dfs序 中搞 线段树 就行. ——代码 #include <cstdio ...
- 如何在Eclipse中生成Native类对应的JNI的.h文件
1 致谢 感谢super_level网友 他的博客写的很清楚 给了我很多帮助 链接如下:http://blog.csdn.net/super_level/article/details/2124353 ...
- spring mvc dispatcherServlet
1. 在web.xml中配置servlet对相应的url请求进行处理 <servlet> <servlet-name>springDispatcher</servlet- ...
- flex里InputText不能输入中文
最近做项目都没做任何的更新,今天突然遇到在flex里的InputText无法进行中文输入,晚上查找了下资料,很多原因说是flashplayer的一个BUG. 在网上找到两种解决办法: 1.会出现这种情 ...
- Distinct Subsequences (dp)
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence ...