一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

搭建EXTJS和STRUTS2框架(ext和struts2簡單實(shí)例)

新建一個工程struts2工程teaweb(因?yàn)楝F(xiàn)在所做的項(xiàng)目是一個關(guān)于茶葉,茶文化的),導(dǎo)入jar包(基本的幾個jar包:commons-logging-1.0.4.jar,freemarker- 2.3.8.jar,ognl-2.6.11.jar,struts2-core-2.0.10.jar,xwork-2.0.4.jar),配置 struts.xml配置內(nèi)容如下

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.action.extension" value="ph" />
<constant name="struts.multipart.maxSize" value="1000000000"/>
<package name="teaweb" extends="json-default" namespace="/">
<action name="test" class="com.teaweb.action.TestAction">

<result type="json"></result>
</action>
</package>
</struts>

 注意此處的:extends="json-default" ,<result type="json"></result>

配置web.xml,內(nèi)容如下:

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

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.ph</url-pattern>
</filter-mapping>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.jsp</url-pattern>
</filter-mapping>
<jsp-config>
<taglib>
<taglib-uri>/WEB-INF/struts-tags.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-tags.tld</taglib-location>
</taglib>
</jsp-config>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

 新建一個Java類為TestAction,Java代碼為:

package com.teaweb.action;

import Java.io.IOException;
import Java.io.UnsupportedEncodingException;
import Java.util.List;
import com.teaweb.bean.TestBean;
import com.teaweb.dao.TestDAO;

public class TestAction extends PublicAction {
private TestBean testBean;
private long results;
private TestDAO testDAO=new TestDAO();
private List list;
public String select() {
// TODO Auto-generated method stub
response.setCharacterEncoding("gb2312");
list=testDAO.select();
results=list.size();
return SUCCESS;
}
public String login() {
// TODO Auto-generated method stub
try {
request.setCharacterEncoding("utf-8");
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
response.setCharacterEncoding("gb2312");
TestBean result=testDAO.selectbyname(testBean);
if(result!=null){
outString("{success:true,msg:'"+result.getName()+"登錄成功'}");
}else{
outString("{failure:true,msg:'登錄失敗'}");
}
return null;
}


public TestBean getTestBean() {
return testBean;
}

public void setTestBean(TestBean testBean) {
this.testBean = testBean;
}

public List getList() {
return list;
}

public void setList(List list) {
this.list = list;
}

public long getResults() {
return results;
}

public void setResults(long results) {
this.results = results;
}


}

 其中TestBean 是一個實(shí)體類,還有一個連接數(shù)據(jù)庫查詢的方法,只要能查出為List結(jié)果就可以了

我這里做了一個登陸和查詢所有TEST表里的信息兩個方法

其中l(wèi)ogin.jsp代碼為:

<%@ page language="Java" import="Java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'login.jsp' starting page</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="/ext2/resources/css/ext-all.css" />
<script type="text/Javascript" src="/ext2/adapter/ext/ext-base.js"></script>
<script type="text/Javascript" src="/ext2/ext-all.js"></script>
</head>
<body>
<script type="text/Javascript">
Ext.onReady(function(){
Ext.QuickTips.init();
var form1=new Ext.FormPanel({
renderTo:"panel1",
width:500,
height:300,
frame:true,
title:"ajax提交",
collapsible:true,
minButtonWidth:60,
labelAlign:"right",
defaultType:"textfield",
url:"test!login.ph",
items:[{
fieldLabel:"用戶名",
id:"txtName",
name:'testBean.name',
allowBlank:false,
blankText:"用戶名不能為空!"
},{
fieldLabel:"密碼",
allowBlank:false,
blankText:"密碼不能為空!",
name:'testBean.password',
inputType:'password'
},{
fieldLabel:"備注"
}],
buttons:[{
text:"提交",
handler:function(){
if(form1.getForm().isValid()) {
form1.getForm().submit({
success:function(from,action) {
Ext.Msg.alert("返回提示",action.result.msg);
window.location = 'index.jsp';
},
failure:function(form,action) {
Ext.Msg.alert("返回提示",action.result.msg);
}
});
}
}
},{
text:"重置",
handler:function() {
form1.getForm().reset();
}
}]
});

});
</script>
<div id="panel1"> </div>
</body>
</html>

 其中index.jsp頁面代碼為:

<%@ page language="Java" import="Java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>index</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<link rel="stylesheet" type="text/css" href="/ext2/resources/css/ext-all.css" />
<script type="text/Javascript" src="/ext2/adapter/ext/ext-base.js"></script>
<script type="text/Javascript" src="/ext2/ext-all.js"></script>
</head>
<body>
<script type="text/Javascript">
Ext.onReady(function(){
var store=new Ext.data.JsonStore({
url:"test!select.ph",
totalProperty: "results",
root: "list",
fields:[{name:'id',mapping:'id'}, {name:'name',mapping:'name'},{name:'password',mapping:'password'}]
});
store.load();
var gird=new Ext.grid.GridPanel({
renderTo:"hello",
title:"歡迎登錄",
height:150,
width:300,
columns:[
{header:"編號",dateindex:"id"},
{header:"賬號",dateindex:"name"},
{header:"密碼",dateindex:"password"}
],
store:store,
autoExpandColumn:2
})
})
</script>
<div id="hello"> </div>
</body>
</html>

jsp技術(shù)搭建EXTJS和STRUTS2框架(ext和struts2簡單實(shí)例),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 国产高清国内精品福利99久久 | 亚洲一区二区三区在线免费观看 | 91视频最新| 一木道一二三区精品 | 国产精品欧美亚洲 | 日韩久久网 | 午夜激情视频专区在线观看网站大全 | 四虎在线最新地址4hu | 国产一级特黄一级毛片 | 男女男精品视频网站 | 久久午夜精品2区 | 综合国产在线 | 91精品免费国产高清在线 | 黄色在线观看网站 | 91免费福利视频 | 五月婷婷激情综合网 | 国外免费精品视频在线观看 | 69精品在线观看 | 视频一区 中文字幕 | 毛片99| 国产成人综合亚洲欧美在线n | 日韩a无v码在线播放免费 | 日韩经典欧美精品一区 | 欧美另类极品videosbest视频 | 亚瑟成人影院 | 国产一区二区精品久久 | 日本韩国理论片大全在线 | 综合激情网五月 | 色婷婷久久综合中文久久一本 | 亚洲一区二区三区高清网 | 狠狠做久久深爱婷婷97动漫 | 狠狠色影院 | 国产精品福利小视频 | www.色噜噜 | 欧美日本高清视频在线观看 | 伊人亚洲综合 | 五月sese| 男女男精品视频免费观看 | 久久久这里只有精品加勒比 | 一区二区三区免费视频网站 | 国内精品视频在线播放 |