基於struts環境下的jquery easyui環境搭建

下載地址:

https://download.csdn.net/detail/cyberzhaohy/7348451

添加瞭json包:jackson-all-1.8.5.jar,項目結構如下:

測試網址:

https://localhZ喎?/kf/ware/vc/” target=”_blank” class=”keylink”>vc3Q6OTA5MC9qcXVlcnktZWFzeXVpLTEuMi42QmFzZWRvblN0cnV0cy9sYXlvdXQuanNwPC9wPgo8cD7Qp7n7zbzI58/Co7o8YnI+CjwvcD4KPHA+PGltZyBzcmM9″/uploadfile/Collfiles/20140515/20140515090646134.jpg” alt=”\”>

配置文件web.xml:

<web-app
version="2.4"
xmlns="https://java.sun.com/xml/ns/j2ee"

xmlns:xsi=”https://www.w3.org/2001/XMLSchema-instance”

xsi:schemaLocation=”https://java.sun.com/xml/ns/j2ee

https://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”>

index.jsp

org.springframework.web.context.ContextLoaderListener

contextConfigLocation

classpath:beans.xml

openSessionInView

org.springframework.orm.hibernate3.support.OpenSessionInViewFilter

sessionFactoryBeanName

sf

openSessionInView

/*

struts2

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

struts2

/*

beans.xml配置,上面配置文件黃色代碼sf使用下面黃色代碼配置:

<beans
xmlns="https://www.springframework.org/schema/beans"

xmlns:xsi=”https://www.w3.org/2001/XMLSchema-instance”

xmlns:context=”https://www.springframework.org/schema/context”

xmlns:aop=”https://www.springframework.org/schema/aop”

xmlns:tx=”https://www.springframework.org/schema/tx”

xsi:schemaLocation=”https://www.springframework.org/schema/beans

https://www.springframework.org/schema/beans/spring-beans-2.5.xsd

https://www.springframework.org/schema/context

https://www.springframework.org/schema/context/spring-context-2.5.xsd

https://www.springframework.org/schema/aop

https://www.springframework.org/schema/aop/spring-aop-2.5.xsd

https://www.springframework.org/schema/tx

https://www.springframework.org/schema/tx/spring-tx-2.5.xsd”>

<bean

class=”org.springframework.beans.factory.config.PropertyPlaceholderConfigurer”>

classpath:jdbc.properties

<bean
id="dataSource"

class=”org.apache.commons.dbcp.BasicDataSource”

destroy-method=”close”>

<property
name="driverClassName"

value=”${jdbc.driverClassName}”/>

<bean
id="sf"

class=”org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean”>

com.xdy.registration.model

org.hibernate.dialect.OracleDialect

true

<bean
id="hibernateTemplate"

class=”org.springframework.orm.hibernate3.HibernateTemplate”>

<bean
id="txManager"

class=”org.springframework.orm.hibernate3.HibernateTransactionManager”>

expression=”execution(public* com.xdy.registration.service.*.*(..))”>

advice-ref=”txAdvice”/>

控制邏輯struts.xml配置:

class=”com.xdy.registration.action.UserAction”>

/registerSuccess.jsp

/registerFail.jsp

/UserList.jsp

/User.jsp

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
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 getUsers() {

returnusers;

}

publicvoid setUsers(List 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代碼:

<%

String path = request.getContextPath();

String basePath = request.getScheme() +
“://”

+ request.getServerName() +
“:” + request.getServerPort()

+ path +
“/”;

%>

<base
href="”>

My JSP’layout.jsp’ starting page

<!–

–>

<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”>

<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>

<p
region="north"
title="NorthTitle"

style=”height:100px;”>

<p
region="south"
title="southTitle"
split="true"

style=”height:100px;”>

<p
region="west"
title="westTitle"
split="true"
collapse="true"

style=”width:200px;”>

被引入代碼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:’密碼’,

field:’password’,

width:100

}]]

});

});

</script>

發佈留言