木叶下521 2013-07-29 15:20
浏览 1625
已采纳

response.sendRedirect()跳转页面无法显示

出现一个新问题:center_left.jsp,内容是Ext的一个form表单,

1
url:'servlet/AddQueServlet',
具体如下:

001

002 Ext.require([ '*' ]); 003 Ext.onReady(function() {//onReady()函数在页面注册多个函数,依次执行 004 Ext.QuickTips.init(); 005 Ext.state.Manager.setProvider(Ext.create('Ext.state.CookieProvider')); 006 // NOTE: This is an example showing simple state management. During development, 007 // it is generally best to disable state management as dynamically-generated ids 008 // can change across page loads, leading to unpredictable results. The developer 009 // should ensure that stable state ids are set for stateful components in real apps. 010 Ext.state.Manager.setProvider(Ext 011 .create('Ext.state.CookieProvider')); 012 013 //表单组合控件在中间部分的左侧 014 var form = new Ext.form.FormPanel({ 015 labelAlign : 'right', 016 autoScroll : true, 017 labelWidth : 50, 018 width : 600, 019 // title: 'form', 020 frame : true, 021 url:'servlet/AddQueServlet', 022 items : [ { 023 layout : 'form', 024 items : [ { 025 //columnWidth:.7, 026 xtype : 'fieldset', 027 layout : 'form', 028 checkboxToggle : true,//折叠fieldset 029 title : '文字输入', 030 autoHeight : true, 031 defaults : { 032 width : 400 033 }, 034 defaultType : 'textfield', 035 items : [ { 036 fieldLabel : '题目', 037 name : 'head', 038 allowBlank : false 039 }, { 040 041 xtype : 'htmleditor', 042 fieldLabel : '题目备注及说明', 043 id : 'editor', 044 anchor : '98%', 045 name : 'des', 046 fontFamilies: ["宋体", "隶书", "黑体","Times New Roman"] 047 048 }, { 049 xtype : 'hidden', 050 name : 'hidden' 051 } ] 052 }, { 053 //columnWidth:.3, 054 055 xtype : 'fieldset', 056 checkboxToggle : true, 057 title : '数据验证', 058 autoHeight : true, 059 defaultType : 'checkbox', 060 hideLabels : true, 061 layout : 'column', 062 name:'checkValue', 063 //style: 'margin-left:10px;', 064 //bodyStyle: 'margin-left:20px;', 065 items : [ { 066 boxLabel : '必填', 067 columnWidth : .125, 068 name : 'check', 069 inputValue : '1', 070 checked : true, 071 width : 'auto' 072 }, { 073 boxLabel : '手机号码', 074 columnWidth : .125, 075 name : 'check', 076 inputValue : '2', 077 //checked: true, 078 width : 'auto' 079 }, { 080 boxLabel : '邮编', 081 columnWidth : .125, 082 name : 'check', 083 inputValue : '3', 084 width : 'auto' 085 }, { 086 boxLabel : '身份证号', 087 columnWidth : .125, 088 name : 'check', 089 inputValue : '4', 090 width : 'auto' 091 }, { 092 boxLabel : '日期', 093 columnWidth : .125, 094 name : 'check', 095 inputValue : '5', 096 width : 'auto' 097 }, { 098 boxLabel : 'Email', 099 columnWidth : .125, 100 name : 'check', 101 inputValue : '6', 102 width : 'auto' 103 }, { 104 boxLabel : '必答题', 105 columnWidth : .25, 106 name : 'check', 107 inputValue : '7', 108 width : 'auto' 109 } ] 110 }, { 111 xtype : 'fieldset', 112 checkboxToggle : true, 113 title : '选项(每行一个)', 114 autoHeight : true, 115 defaultType : 'textarea', 116 hideLabels : true, 117 layout:'form', 118 //style: 'margin-left:10px;', 119 //bodyStyle: 'margin-left:20px;', 120 items : [ { 121 xtype:'textfield', 122 fieldLabel : '输入选项个数', 123 name : 'number' 124 },{ 125 width : 400, 126 grow : true, 127 name : 'options', 128 //allowBlank : false, 129 emptyText : '输入选项', 130 maxLength : 10, 131 minLength : 2 132 } ] 133 }, { 134 xtype : 'fieldset', 135 //checkboxToggle:true, 136 title : '选项排列', 137 autoHeight : true, 138 defaultType : 'radio', 139 hideLabels : true, 140 layout : 'column', 141 //style: 'margin-left:10px;', 142 //bodyStyle: 'margin-left:20px;', 143 items : [ { 144 145 boxLabel : '横向', 146 name : 'rank', 147 inputValue : '1', 148 //checked: true, 149 width : 'auto' 150 }, { 151 152 boxLabel : '竖向', 153 name : 'rank', 154 inputValue : '2', 155 checked : true, 156 width : 'auto' 157 } ] 158 } ] 159 160 } ], buttons: [{ 161 text: '保存', 162 handler:function(){ 163 form.getForm().submit(); 164 } 165 },{ 166 text: '读取' 167 },{ 168 text: '取消' 169 }] 170 }); 171 var viewport = Ext.create('Ext.Viewport', 172 { 173 id : 'Center_left', 174 layout : 'fit', 175 autoScroll : true, 176 items : [form] 177 }); 178 form.render("form"); 179 }); 180 181 182

AddQueServlet如下:
01
public class AddQueServlet extends HttpServlet {
02
public void doGet(HttpServletRequest request, HttpServletResponse response)
03
throws ServletException, IOException {
04
response.setContentType("text/html");
05
doPost(request, response);// 调用doPost方法
06
}
07

08
public void doPost(HttpServletRequest request, HttpServletResponse response)
09
throws ServletException, IOException {
10
request.setCharacterEncoding("utf-8");
11
response.setContentType("text/html;utf-8");
12
response.setCharacterEncoding("utf-8");
13
// 获得表单提交的参数
14
String head=request.getParameter("head");
15
String des=request.getParameter("des");
16
int number=0;
17
if(request.getParameter("number")!=""){
18
number= Integer.parseInt(request.getParameter("number"));
19
}
20

21
//System.out.print(number+"###################");
22
String body=request.getParameter("options");
23
String checkValue[]= request.getParameterValues("check");
24
int rank=Integer.parseInt(request.getParameter("rank"));
25
//System.out.print(rank+"###################");
26
HttpSession session=request.getSession();
27

28

29
//int qt_id = Integer.parseInt((String)session.getAttribute("qt_id"));// 获得所选问题类型的ID
30
//System.out.print(qt_id);
31
int qt_id =1;
32
QuestionType qType = new QuestionType();
33

34

35
QuestionTypeDao questionType = new QuestionTypeDaoImpl();
36
qType = questionType.findQueTypeById(qt_id);
37
Questions question = new Questions();
38

39
question.setQ_head(head);
40
question.setQ_body(body);
41
question.setQ_type(qType);
42
question.setQ_number(number);
43

44

45

46
QuestionsDao questionsDao = new QuestionsDaoImpl();
47
questionsDao.add(question);// 调用实现类的的添加方法
48

49
response.sendRedirect("../DesignQuestions/Center_right.jsp");// 重定向到显示全部的Servlet中
50
}
51
}
view sourceprint?
1
问题就是:Center_right.jsp无法显示,在表单里点击保存后,页面不跳转,也不报错!大侠们,说说答案吧

  • 写回答

1条回答 默认 最新

  • wuxiaoxu666 2013-07-30 10:19
    关注

    Ext 提交表单用的异步提交Ajax。Ajax在发送请求时后台返回的数据(json或者html页面)在其回调函数中处理。 你这个相当于后台把Center_right.jsp页面已经返回给前台了但是前台回调函数中没有处理。
    方法:
    1.请求成功过后他返回下个页面的url,通过js直接去请求相应页面 如window.location.href="Center_right.jsp"
    2.或者拿到后台页面后通过document.getElementById('??').html=responseText;直接修改页面内容

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥20 双层网络上信息-疾病传播