jpbillow 2008-11-13 23:07
浏览 241
已采纳

关于ext提交表单的问题

如果有ext + serlvet登录表单提交的例子,麻烦传给我一份.javabillow@hotmail.com.谢谢了.

ext的代码如下:
[code="html"]








Ext.onReady(function(){ Ext.QuickTips.init(); Ext.form.Field.prototype.msgTarget = 'side'; var simple = new Ext.FormPanel({ labelWidth: 75, baseCls: 'x-plain', defaults: {width: 150}, defaultType: 'textfield', items: [{ fieldLabel: '帐户', name: 'name', allowBlank:false, blankText:'帐户不能为空' },{ inputType:'password', fieldLabel: '密码', name: 'pwd', allowBlank:false, blankText:'密码不能为空' } ], buttons: [{ text: '登录系统', type: 'submit', handler:function(){ if(simple.form.isValid()){ simple.form.doAction('submit',{ url:'../test2',//'login.jsp', method:'post', params:'', success:function(form,action){ alert(action.result.msg); }, failure:function(){ alert(22); } }); } } }] }); win = new Ext.Window({ id:'win', title:'用户登陆', layout:'fit', width:300, height:150, plain:true, bodyStyle:'padding:5px;', maximizable:false, closeAction:'close', closable:false, collapsible:true, plain: true, buttonAlign:'center', items:simple }); win.show(); });









[/code]

login.jsp的代码如下:
[code="html"]
<%@ page contentType="text/html; charset=UTF-8"%>

<%

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

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

out.println("{success:true,msg:\'ok\'}");

//out.close();
%>

[/code]

Test2.java的代码如下:
[code="java"]
package javaFile;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class Test2 extends HttpServlet{

/**
 * @param args
 */
public void doGet ( HttpServletRequest request , HttpServletResponse response )  
throws ServletException , IOException   {
    response.setContentType("text/html");   
    response.setCharacterEncoding("UTF-8"); 
    PrintWriter out=response.getWriter();
    out.print("{success:true,msg:\'ok\'}");
    out.close();
}
public void doPort ( HttpServletRequest request , HttpServletResponse response )  
throws ServletException , IOException   {
        doGet(request,response);
}

}
[/code]

问题有两个。
一个是我在同一个环境中,url:'login.jsp'时,可以返回ok。
url:'../test2'时,弹出alert(22)。

另一个是login.jsp中如果释放注掉的//out.close();
会报java.io.IOException: Stream closed
at org.apache.jasper.runtime.JspWriterImpl.ensureOpen(JspWriterImpl.java:204)

错误。
为什么?谢谢。
[b]问题补充:[/b]
如果有ext + serlvet登录表单提交的例子,麻烦传给我一份.
javabillow@hotmail.com.谢谢了.

非常感谢bohemia.
jsp输出的问题我明白了.另一个问题去了点也不可以.是我没说清楚.

补充一下.
myeclipse建的web project
context 为/
http://localhost:8080/test2 可以访问到Servlet
webroot下有html文件夹,里面放test2.html
http://localhost:8080/html/test2.html 可以访问.
早上查了下,大概是相对路径和绝对路径不明白.麻烦谁帮我看一下.谢谢.

test2.html的代码如下:

<html>   
<head>   
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />   
<title></title>   
<link rel="stylesheet" type="text/css" href="../ext/resources/css/ext-all.css" />   
<script type="text/javascript" src="../ext/adapter/ext/ext-base.js"></script>   
<script type="text/javascript" src="../ext/ext-all.js"></script>  
<script type="text/javascript">   

Ext.onReady(function(){    
          
          Ext.QuickTips.init();   
          Ext.form.Field.prototype.msgTarget = 'side'; 
      
          
          var simple = new Ext.FormPanel({   
                labelWidth: 75,                
                baseCls: 'x-plain',   
                defaults: {width: 150},   
                defaultType: 'textfield',
                    
                
                items: [{   
                        fieldLabel: '帐户',   
                        name: 'name',
                        allowBlank:false,
                        blankText:'帐户不能为空'  
                    },{   
                        inputType:'password',   
                        fieldLabel: '密码',
                        name: 'pwd',   
                        allowBlank:false,   
                        blankText:'密码不能为空'  
                    }   
                ],   
  
                buttons: [{   
                    text: '登录系统',   
                    type: 'submit',   
                    
                    handler:function(){   
                              if(simple.form.isValid()){
 
                                  
                                  simple.form.doAction('submit',{   
                                     url:'../test2',//'login.jsp',
                                     method:'post',   
                                     params:'',   
                                     
                                     success:function(form,action){   
                                            alert(action.result.msg);
                                     },   
                                     
                                     failure:function(){ 
                                            alert(22);    
                                     }   
                                  });   
                               }                                                          
                    }   
                }]   
            });       
                   
                   win = new Ext.Window({   
                        id:'win',   
                        title:'用户登陆',   
                        layout:'fit',                  
                        width:300,   
                        height:150,   
                        plain:true,   
                        bodyStyle:'padding:5px;',   
                        maximizable:false,
                        closeAction:'close',   
                        closable:false,
                        collapsible:true,
                        plain: true,   
                        buttonAlign:'center',   
                        items:simple
                    });   
                    win.show();   
                                           
         });   
</script>   
</head>   
<body>   
</body>   
</html>  

login.jsp的代码如下:

<%@ page contentType="text/html; charset=UTF-8"%>   

<%   
    String name = request.getParameter("name");   
    String pwd = request.getParameter("pwd");   
    out.println("{success:true,msg:\'ok\'}");          
    //out.close();
%>  

Test2.java的代码如下:

package javaFile;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class Test2 extends HttpServlet{

    /**
     * @param args
     */
    public void doGet ( HttpServletRequest request , HttpServletResponse response )  
    throws ServletException , IOException   {
        response.setContentType("text/html");   
        response.setCharacterEncoding("UTF-8"); 
        PrintWriter out=response.getWriter();
        out.print("{success:true,msg:\'ok\'}");
        out.close();
    }
    public void doPort ( HttpServletRequest request , HttpServletResponse response )  
    throws ServletException , IOException   {
            doGet(request,response);
    }
}

问题有两个。
一个是我在同一个环境中,url:'login.jsp'时,可以返回ok。
url:'../test2'时,弹出alert(22)。

另一个是login.jsp中如果释放注掉的//out.close();
会报java.io.IOException: Stream closed
at org.apache.jasper.runtime.JspWriterImpl.ensureOpen(JspWriterImpl.java:204)

错误。
为什么?谢谢。

  • 写回答

2条回答 默认 最新

  • bohemia 2008-11-14 14:29
    关注

    [quote]public void doPort ( HttpServletRequest request , HttpServletResponse response )

    throws ServletException , IOException {
    doGet(request,response); [/quote]

    [color=red]应该是 doPost吧?[/color]
    如果你/login.jsp可以访问;
    那你 /test2也应该可以访问才对;

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

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大