木叶下521 2013-07-31 19:43
浏览 330
已采纳

JSp页面传值和Ext JS表单自动填充

有一个JSP文件:Center_right.jsp
[code="java"]










<%
while (it.hasNext()) {
    Questions q=(Questions)it.next();

%>










<%
}
list.clear();
%>

题目编号 题目内容 题目类型 选项个数 选 项 题目备注 操作
<%= q.getQ_id()%> <%= q.getQ_head()%> <%= q.getQ_type().getQt_des()%> <%= q.getQ_number()%> <%= q.getQ_body()%> <%= q.getQ_remarks()%> ">删除

首页||
"> 下一页 ||
Ext.require([ '*' ]); Ext.onReady(function() {//onReady()函数在页面注册多个函数,依次执行 Ext.QuickTips.init(); Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider')); Ext.state.Manager.setProvider(Ext .create('Ext.state.CookieProvider')); //表单组合控件 var form = new Ext.form.FormPanel({ labelAlign : 'right', autoScroll : true, labelWidth : 50, width : 600, // title: 'form', frame : true, //reader:reader, //standardSubmit:true, //url:'servlet/AddQueServlet', items : [ { layout : 'form', items : [ { //columnWidth:.7, xtype : 'fieldset', layout : 'form', checkboxToggle : true,//折叠fieldset title : '文字输入', autoHeight : true, defaults : { width : 400 }, defaultType : 'textfield', items : [ { fieldLabel : '题目', name : 'head', allowBlank : false }, { xtype : 'htmleditor', fieldLabel : '题目备注及说明', id : 'editor', anchor : '98%', name : 'remarks', fontFamilies: ["宋体", "隶书", "黑体","Times New Roman"] }, { xtype : 'hidden', name : 'hidden' } ] }, { //columnWidth:.3, xtype : 'fieldset', checkboxToggle : true, title : '数据验证', autoHeight : true, defaultType : 'checkbox', hideLabels : true, layout : 'column', name:'checkValue', //style: 'margin-left:10px;', //bodyStyle: 'margin-left:20px;', items : [ { boxLabel : '必填', columnWidth : .125, name : 'check', inputValue : '1', checked : true, width : 'auto' }, { boxLabel : '手机号码', columnWidth : .125, name : 'check', inputValue : '2', //checked: true, width : 'auto' }, { boxLabel : '邮编', columnWidth : .125, name : 'check', inputValue : '3', width : 'auto' }, { boxLabel : '身份证号', columnWidth : .125, name : 'check', inputValue : '4', width : 'auto' }, { boxLabel : '日期', columnWidth : .125, name : 'check', inputValue : '5', width : 'auto' }, { boxLabel : 'Email', columnWidth : .125, name : 'check', inputValue : '6', width : 'auto' }, { boxLabel : '必答题', columnWidth : .25, name : 'check', inputValue : '7', width : 'auto' } ] }, { xtype : 'fieldset', checkboxToggle : true, title : '选项(每行一个)', autoHeight : true, defaultType : 'textarea', hideLabels : true, layout:'form', //style: 'margin-left:10px;', //bodyStyle: 'margin-left:20px;', items : [ { xtype:'textfield', fieldLabel : '输入选项个数', name : 'number' },{ width : 400, grow : true, name : 'options', //allowBlank : false, emptyText : '输入选项', maxLength : 10, minLength : 2 } ] }, { xtype : 'fieldset', //checkboxToggle:true, title : '选项排列', autoHeight : true, defaultType : 'radio', hideLabels : true, layout : 'column', //style: 'margin-left:10px;', //bodyStyle: 'margin-left:20px;', items : [ { boxLabel : '横向', name : 'rank', inputValue : '1', //checked: true, width : 'auto' }, { boxLabel : '竖向', name : 'rank', inputValue : '2', checked : true, width : 'auto' } ] } ] } ], buttons: [{ text: '保存', handler: function(){ //此处可以用myFormPanel.getForm()和myFormPanel.form两种方法获得表单对象. form.getForm().submit({//提交表单数据 url: 'servlet/AddQueServlet',//处理页面,注意返回内容格式的正确性 method: 'post', success: function(form, action) {//保存成功 Ext.Msg.alert('保存成功', action.result.msg); }, failure: function(form, action) {//保存失败 Ext.Msg.alert('保存失败', action.result.msg); } }) ; } },{ text: '重置', handler: function(){ form.form.reset() ;//重置表单 } }] }); form.getForm().load({ url: 'DesignQuestions/ShowQueByIdJson.jsp', params: { id: 'load' }, failure: function(form, action) { Ext.Msg.alert("Load failed", action.result.errorMessage); }, success:function(form, action) { Ext.Msg.alert("Load success", action.result.errorMessage); } }); var viewport = Ext.create('Ext.Viewport', { id : 'Center_left', layout : 'fit', autoScroll : true, items : [form] }); form.render("form"); });


<%
String qID=request.getParameter("q_id");
session.setAttribute("q_id", qID);
//System.out.print(qID);
%>[/code]
这个表单我想要自动填充,从ShowQueByIdJson.jsp获取值:
[code="java"]<%

int q_id = Integer.parseInt((String)session.getAttribute("q_id"));// 获得页面传递的参数
Questions q = new Questions();
QuestionsDao questionDao = new QuestionsDaoImpl();
q = questionDao.findQuestionsById(q_id);// 调用实现类中根据id查询的方法 %>

<%

String id = request.getParameter("id") ;

if(id!=null &&"load".equals(id)){

%>

{

success: true,

data: {

head: "${q.q_head }",

remarks: "${q.q_remarks }",

number:"${q.q_number }",

options: ${q.q_body }"
}

}

<%

}else{

%>

{

success: false,

msg: "数据载入错误"

}

<%

}

%> [/code]

问题来啦!session范围是一个会话,这个q_id传不到ShowQueByIdJson.jsp,所以查不到数据写进JSON字符串,怎样才能达到:点击修改,跳转到表单的页面能够把应该的信息都填充的效果?

  • 写回答

3条回答 默认 最新

  • iteye_15549 2013-08-01 17:49
    关注

    不对,form.getForm().load({
    url: 'DesignQuestions/ShowQueByIdJson.jsp',
    params: {
    id: 'load' ,
    [size=medium][color=red] q_id:<%=request.getParameter("q_id");%>[/color][/size]
    },
    failure: function(form, action) {
    Ext.Msg.alert("Load failed", action.result.errorMessage);
    },
    success:function(form, action) {
    Ext.Msg.alert("Load success", action.result.errorMessage);
    }
    })

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀