如果有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)
错误。
为什么?谢谢。