1. ext的formPanel表單的提交不少人都知道,可是如何用ext提交html頁面普通的表單?javascript
2. 在這裏提供小的例子代碼簡單就不提供文件了,現將代碼貼給你們分享。css
3. jsp代碼以下只包含一個簡單的formhtml
Java代碼 java
<%@ page language="java" contentType="text/html; charset=UTF-8" 數據庫
pageEncoding="UTF-8"%> json
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> bootstrap
<html> app
<head> jsp
<script type="text/javascript"> post
var contextPath="<%=request.getContextPath()%>";
</script>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="ext-4.0.7/resources/css/ext-all.css" />
<script type="text/javascript" src="ext-4.0.7/bootstrap.js"></script>
<script type="text/javascript" src="js/extjs3.js"></script>
</head>
<body>
<form action="" id="userForm" method="post">
c_nme:<input type="text" id="c_nme" name="c_nme"/><br/>
c_sex:<input type="text" id="c_sex" name="c_sex"/><br/>
<input type="button" onclick="saveUser()" value="submit">
</form>
</body>
</html>
4. 提供js代碼以下這裏用struts1(struts2請自行配置url)
Java代碼
function saveUser() {
Ext.Ajax.request({
url: contextPath+"/secured/cust/custController.do?method=saveUser",
method: "POST",
<span style="color: #ff0000;"> form : 'userForm',//這裏爲html表單名(必須有)</span>
success: function (response, option) {
response = Ext.JSON.decode(response.responseText);
if (response.success == true) {
if (response.flag == true) {
Ext.MessageBox.alert("提示", "保存信息成功!");
Ext.getCmp('gridpanel').store.load(); //刷新列表
}else {
Ext.MessageBox.alert("錯誤信息", "保存信息失敗!");
}
}else { Ext.MessageBox.alert("錯誤信息", response.msges); }
},
failure: function () { Ext.Msg.alert("提示", "保存失敗<br>沒有捕獲到異常"); }
});
}
5. 提供action中方法以下(這裏沒有鏈接數據庫)
Java代碼
public ActionForward saveUser(ActionMapping iMapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
try {
CustForm theForm = (CustForm) form;
String name = theForm.getC_nme();
String sex = theForm.getC_sex();
System.out.println(name+" "+sex);
response.setCharacterEncoding("UTF-8");
response.setHeader("Cache-Control", "no-cache,must-revalidate");
response.setHeader("Pragma", "no-cache");
response.setDateHeader("Expires", 0);
// json.put("state", 1); // 成功標誌
response.getWriter().print("{success :false,flag:true,msges:'測試'}");
} catch (Exception e) {
log.error(e.getMessage() + "刪除table異常", e);
}
return null;
}