我是 sencha touch 2 框架的新手,我正在尝试创建一个简单的学生应用程序,用户可以在其中登录并添加、删除和更新现有记录。我想使用 MySQL db 验证用户。我有一个问题,我希望我的应用程序将用户名和密码发送到我的 jsp 页面进行验证,并在成功验证后获取整个记录以显示在下一页的 sencha 上,但无法这样做。我正在使用 Store 加载数据并将字段与 db 的列名匹配。谁能帮助我如何将参数(用户名和密码)发送到我的jsp页面,并在登录时在下一页显示获取的记录。
这是我的代码:
Model :-
Ext.define('MyApp.model.Login', {
extend: 'Ext.data.Model',
config: {
fields: [
{
name: 'userName',
type: 'string'
},
{
name: 'password',
type: 'string'
}
]
}
});
Store :-
Ext.define('MyApp.store.Login', {
extend: 'Ext.data.Store',
requires: [
'MyApp.model.Login'
],
config: {
autoLoad: true,
model: 'MyApp.model.Login',
storeId: 'loginStore',
proxy: {
type: 'ajax',
url: 'http://localhost:8080/StudentApplication/AddStudent.jsp?',
reader: {
type: 'json',
rootProperty: 'user'
}
}
},
});
View :-
Ext.define('MyApp.view.MyContainer', {
extend: 'Ext.Container',
stores : [ 'loginStore' ],
requires : ['MyApp.store.Login', 'Ext.List', 'Ext.DataView', 'Ext.data.Store'],
config: {
items: [
{
xtype: 'panel',
centered: true,
height: 272,
items: [
{
xtype: 'textfield',
label: 'UserName',
itemId: 'user',
labelWidth: '50%',
required : true,
placeHolder: 'User'
},
{
xtype: 'textfield',
label: 'Password',
itemId: 'pass',
required : true,
labelWidth: '50%',
placeHolder: 'Password'
},
{
xtype: 'button',
centered: true,
id: 'Login',
itemId: 'mybutton',
ui: 'round',
width: '50%',
text: 'Login'
}
]
}
],
listeners: [
{
fn: 'onMybuttonTap',
event: 'tap',
delegate: '#mybutton'
}
]
},
onMybuttonTap: function(button, e, eOpts) {
Ext.Msg.alert("Hello All..");;
}
});
app.js :-
Ext.Loader.setConfig({
});
Ext.application({
views: [
'MyContainer'
],
name: 'MyApp',
launch: function() {
Ext.create('MyApp.view.MyContainer', {fullscreen: true});
}
});
我试过你在点击提交按钮时使用 Ext.Ajax.request。作为“response.responseText”的成功功能正在获取整个jsp页面。你能告诉我如何在jsp页面中检索提交的值吗?我还希望当 sencha 调用我的 jsp 页面时,我的 jsp 页面应该运行并执行查询并返回结果。下面是提交按钮代码和我的jsp代码。
onTest_submitTap: function(button, e, eOpts) {
Ext.Msg.alert('Form Submit Clicked !!');
var values = this.getTest(); // This is my view 'App.view.Test'
console.log("Param ::" + values ); // I get the test object here
console.log("Values ::" + Ext.getCmp('test_name').getValue()); // here i get the value of name field in 'Test' View
Ext.Ajax.request({
values : values, // values from form fields..
url: 'http://localhost/jsp/TimeSheet/test_sencha.jsp',
success: function(response) {
console.log("Response is ::"+response.responseText); // Recieved the response as a whole jsp page
},
failure: function(response) {
console.log(response.responseText);
}
});
<%@page language="java" import="java.sql.*, java.util.*, java.lang.*, net.sf.json.*, org.json.simple.JSONObject,com.dipti.User" pageEncoding="UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="application/json; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection connection= DriverManager.getConnection("jdbc:mysql://localhost:3306/test_db?user=root&password=root");
Statement statement = connection.createStatement();
Boolean result = statement.execute("INSERT INTO `employee` (`id`, `Name`, `Age`) VALUES (3, 'sunny', '28');");
out.print(( " Result is :: " + result ));
}
catch (Exception exc)
{
out.print(exc.toString());
}
%>
</body>
</html>