form自动加载数据

来源:互联网 发布:ubuntu软件源国内镜像 编辑:程序博客网 时间:2024/06/05 05:59

http://www.iteye.com/topic/149652

 

<%@ 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>
<title>简单的表单例子</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="css/ext-all.css">
</head>
<body>
<script type="text/javascript" src="js/ext-base.js"></script>
<script type="text/javascript" src="js/ext-all.js"></script>
<script type="text/javascript" src="js/ext-lang-zh_CN.js"></script>
<script>
Ext.QuickTips.init();
Ext.form.Field.prototype.msgTarget = 'side';
var simpleForm = new Ext.FormPanel({
    labelAlign: 'left',
    title: '表单例子',
    buttonAlign:'right',
    bodyStyle:'padding:5px',
    width: 600,
    frame:true,
    labelWidth:45,
    waitMsgTarget: true,
    items: [{
        xtype:'tabpanel',
        plain:true,
        activeTab: 0,
        height:235,
        defaults:{bodyStyle:'padding:10px'},
        reader: new Ext.data.JsonReader(  
         {
         successProperty: 'success',
root: 'data'
         },  
         [  
            {name: 'name',mapping:'name'}, // custom mapping
         ]  
        ),  
        items:[{
            title:'属性',
            layout:'column', /**layout:'form'**/
           /** defaults: {width: 230},
            defaultType: 'textfield',**/
            border:false,
            labelSeparator:':',
            items: [{
            columnWidth:.3,
               layout: 'form',
            border:false,
            items: [{
                id:'name',
                xtype:'textfield',
                fieldLabel: '姓名',
                name: 'name',
                anchor:'90%'
            }]
            },{
            columnWidth:.3,
            layout: 'form',
            border:false,
            items: [{
                id:'password',
                xtype:'textfield',
                inputType:'password',
                fieldLabel: '密码',
                name: 'password',
                anchor:'90%'
            }]
            },{
            columnWidth:.4,
               layout: 'form',
            border:false,
            items: [{
            }]
            }
            ]
        },{
            title:'数字时间字母',
            layout:'form',
            defaults: {width: 230},
            defaultType: 'textfield',
            items: [{
                xtype:'numberfield',
                fieldLabel: '数字',
                name: 'number'
            },{
                xtype:'timefield',
                fieldLabel: '时间',
                name: 'time'
            },{
                fieldLabel: '纯字母',
                name: 'char',
                vtype:'alpha'
            }]
        }
});
simpleForm.render(document.body);
simpleForm.load({url: 'test.jsp',method:'post',params:"id=1"}); 

  </script>
</body>
</html>

test.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@page import="java.net.URLDecoder"%>
<%@page import="com.ext.util.*" %>
<%
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>
<title>My JSP 'index.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">
</head>

<body>
<%
String id = request.getParameter("id");
    String name = "123";

String password ="123"

System.out.println("id="+id);
try{
// String json = "{/"success/":true,/"data/":[";
//        json += "{/"name/":/""+name+"/"}";//,{/"password/":"+"/""+password+"/"}
String json = "{success:true,data:";
        json += "{name:'"+name+"'}";
    json += "}";
    response.getWriter().write(json);
    response.getWriter().flush();
    System.out.println(json);
}catch(Exception e){}

%>
</body>
</html>

原创粉丝点击