如何实现JSP和SenchaTouch 2的集成?
我是sencha touch 2框架的新手,我正在尝试创建一个简单的学生应用程序,用户可以登录并添加、删除和更新现有记录。我想使用MySQL数据库验证用户。我遇到的问题是,我希望我的应用程序将用户名和密码发送到我的jsp页面进行验证,验证成功后,获取整个记录以显示在下一页的sencha上,但无法这样做。 我使用Store加载数据,并将字段与db的列名进行匹配。有谁能帮助我将参数(用户名和密码)发送到我的jsp页面,并在登录时在下一页显示获取的记录 这是我的密码:如何实现JSP和SenchaTouch 2的集成?,jsp,extjs,sencha-touch-2,Jsp,Extjs,Sencha Touch 2,我是sencha touch 2框架的新手,我正在尝试创建一个简单的学生应用程序,用户可以登录并添加、删除和更新现有记录。我想使用MySQL数据库验证用户。我遇到的问题是,我希望我的应用程序将用户名和密码发送到我的jsp页面进行验证,验证成功后,获取整个记录以显示在下一页的sencha上,但无法这样做。 我使用Store加载数据,并将字段与db的列名进行匹配。有谁能帮助我将参数(用户名和密码)发送到我的jsp页面,并在登录时在下一页显示获取的记录 这是我的密码: Model :- Ex
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>
onTest\u submitTap:功能(按钮、e、eOpts){
Ext.Msg.alert('点击表单提交!!');
var values=this.getTest();//这是我的视图'App.view.Test'
log(“Param::”+值);//我在这里得到测试对象
console.log(“Values::”+Ext.getCmp('test_name').getValue());//这里我在“test”视图中获得name字段的值
Ext.Ajax.request({
值:值,//来自表单字段的值。。
网址:'http://localhost/jsp/TimeSheet/test_sencha.jsp',
成功:功能(响应){
console.log(“响应为::”+Response.responseText);//作为整个jsp页面接收响应
},
故障:功能(响应){
console.log(response.responseText);
}
});
在此处插入标题
我会使用一个
您的Web服务应该有一个身份验证操作,该操作将用户的凭据作为参数,然后使用它们根据数据库验证其帐户。然后,根据查询的结果,您将需要为该操作生成结果,例如成功和错误
成功返回要显示的数据,错误返回500或任何错误的默认代码…内容无关紧要
在您的请求中,您将获得一个成功和一个失败函数,该函数将加载相应的页面,无论是包含数据的列表还是尝试再次登录的页面
祝你好运,布拉德你好,我找到了插入更新和删除的解决方案,很好用
<%
Connection connection = null;
try {
connection=DBConnect.getConnection();
String empId=request.getParameter("empId");
String Fname=request.getParameter("Fname");
String Lname=request.getParameter("Lname");
String Gender=request.getParameter("GEN");
String DOB=request.getParameter("DOB");
String State=request.getParameter("State");
String City=request.getParameter("City");
String Phone=request.getParameter("Phone");
String Email=request.getParameter("Emailval");
PreparedStatement pst=connection.prepareStatement("insert into employeecdar values(?,?,?,?,?,?,?,?,?)");
pst.setString(1,empId);
pst.setString(2, Fname);
pst.setString(3, Lname);
pst.setString(4, Gender);
pst.setString(5, DOB);
pst.setString(6, State);
pst.setString(7, City);
pst.setString(8, Phone);
pst.setString(9, Email);
int a=pst.executeUpdate();
out.println(a);
out.println(""+"Record added SucessFully Inserted....");
}
catch (Exception e) {
out.println("Somthing Went wrong..");
e.printStackTrace();
}
%>
我试图使用您所说的内容,但遇到了问题。我编辑了问题。请看一下。我建议创建一个单独的登录操作,专门供您的移动应用程序使用,它不会将用户返回到loginsucess.jsp页面,而是返回一个json或xml响应,为您的应用程序提供所需的信息eds来识别用户。我也知道这不是你想要的信息,但我强烈建议不要使用太多java(尤其是你的mysql查询)直接在jsp页面上。这就是struts的全部要点,将显示与逻辑分开。我的错误是,我得到的是HTML格式的响应,但它是JSON格式的。在得到JSON响应后,问题就解决了。