大家好,你们可以叫我大伟,我是extjs的初学者,现在整合struts2.出现的问题是extjs前段form无法传递数据到struts2的action。
具体描述如下:extjs前段代码:
Ext.onReady(function(){
var win = new Ext.Window({
width:600,
height:500,
// xtype:"form",
items:{
itemId:"formmm",
title:'用户基本信息',
labelWidth:60,
width:600,
height:260,
layout:"form",
xtype:"form",
items:[{
border:false,
items:[{
layout:"form",
border:false,
labelWidth:60,
items:[{
itemId:"ddd",
xtype:"textfield",
fieldLabel:"姓名",
name:"name"}]}
]}],//在同一个items中放入按钮
buttons:[{text:"保存",handler:function(){
alert("1");
//var avalue = win.get("ddd").getValue();
alert("2");
// win.getComponent(0).getForm().submit({
// url:"testAjaxActiong.action",
// success:function(form,action){
// alert("保持成功");
// },
// failure:function(form,action){
// alert("wrong");
// }
// });//end button handler
var isTure = win.getComponent(0).form.isValid();
if(isTure){
alert("is true");
win.getComponent(0).form.submit({
waitTitle:'login......',
waitMsg:"server is accepting",
url:"testAjaxActionr.action",
method:"get",
success:function(form,action){
alert("保持成功");
},
failure:function(form,action){
alert("wrong");
}
})
alert("2is true");
}//end headrer
}},//end 第一个button
{text:"取消",handler:function(){win.close()}}]
}//end items
});//end win
win.show();
});
上面有两种方法用submit,大家可以,当我讲url的名字换成CCCCC.action会报错,但是如果正常用struts2配置的action的话不会报错,也不会传递数据到action中。
action的代码:package com.endual.extjs.actions;
import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;import org.apache.struts2.ServletActionContext;
import org.apache.struts2.json.annotations.JSON;import com.opensymphony.xwork2.ActionSupport;public class TestAjaxAction extends ActionSupport{ private String name;
private boolean success;
@Override
public String execute() throws Exception {
System.out.println("**********");//验证是不是进入该action
System.out.print("name" + name);//验证不是传递进来
if(name.equals("admin")){
success = true;
return SUCCESS;
}
success = false;
return SUCCESS;
}
public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
}
struts2的配置文件:<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<constant name="struts.objectFactory" value="spring" />
<package name="ajax" extends="json-default">
<action name="testAjaxAction" class="com.endual.ajax.actions.TestAjaxAction">
<result type="json">
<param name="includeProperties">success</param>
</result>
</action>
</package>
</struts>
现在的问题是:前段无法进入action,也不报错误。大家帮我调试调试啊,谢谢各位朋友。
当然如果您愿意与一起学extjs,我非常乐意,我的QQ:1019990976,麻烦注明:CSDN,extjs
再次谢谢。
具体描述如下:extjs前段代码:
Ext.onReady(function(){
var win = new Ext.Window({
width:600,
height:500,
// xtype:"form",
items:{
itemId:"formmm",
title:'用户基本信息',
labelWidth:60,
width:600,
height:260,
layout:"form",
xtype:"form",
items:[{
border:false,
items:[{
layout:"form",
border:false,
labelWidth:60,
items:[{
itemId:"ddd",
xtype:"textfield",
fieldLabel:"姓名",
name:"name"}]}
]}],//在同一个items中放入按钮
buttons:[{text:"保存",handler:function(){
alert("1");
//var avalue = win.get("ddd").getValue();
alert("2");
// win.getComponent(0).getForm().submit({
// url:"testAjaxActiong.action",
// success:function(form,action){
// alert("保持成功");
// },
// failure:function(form,action){
// alert("wrong");
// }
// });//end button handler
var isTure = win.getComponent(0).form.isValid();
if(isTure){
alert("is true");
win.getComponent(0).form.submit({
waitTitle:'login......',
waitMsg:"server is accepting",
url:"testAjaxActionr.action",
method:"get",
success:function(form,action){
alert("保持成功");
},
failure:function(form,action){
alert("wrong");
}
})
alert("2is true");
}//end headrer
}},//end 第一个button
{text:"取消",handler:function(){win.close()}}]
}//end items
});//end win
win.show();
});
上面有两种方法用submit,大家可以,当我讲url的名字换成CCCCC.action会报错,但是如果正常用struts2配置的action的话不会报错,也不会传递数据到action中。
action的代码:package com.endual.extjs.actions;
import java.io.IOException;
import java.io.PrintWriter;import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;import org.apache.struts2.ServletActionContext;
import org.apache.struts2.json.annotations.JSON;import com.opensymphony.xwork2.ActionSupport;public class TestAjaxAction extends ActionSupport{ private String name;
private boolean success;
@Override
public String execute() throws Exception {
System.out.println("**********");//验证是不是进入该action
System.out.print("name" + name);//验证不是传递进来
if(name.equals("admin")){
success = true;
return SUCCESS;
}
success = false;
return SUCCESS;
}
public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
}
struts2的配置文件:<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd"><struts> <constant name="struts.enable.DynamicMethodInvocation" value="false" />
<constant name="struts.devMode" value="true" />
<constant name="struts.objectFactory" value="spring" />
<package name="ajax" extends="json-default">
<action name="testAjaxAction" class="com.endual.ajax.actions.TestAjaxAction">
<result type="json">
<param name="includeProperties">success</param>
</result>
</action>
</package>
</struts>
现在的问题是:前段无法进入action,也不报错误。大家帮我调试调试啊,谢谢各位朋友。
当然如果您愿意与一起学extjs,我非常乐意,我的QQ:1019990976,麻烦注明:CSDN,extjs
再次谢谢。
解决方案 »
- 这个正则表达式怎么写
- java Statement 获取不到数据 mysql数据库
- JFreeChart组件谁用过。用过的兄弟,进来看看。
- 如何使java开发的应用程序脱离开发平台运行?
- 网上购物的逻辑,我想不通,请指教
- 高分求解——习方法的问题——如何学习源代码?
- 求教一个自定义标签
- Petstore里是通过什么功能是识别访问者的?
- 帮忙!
- j2ee初学, 哪本书合适一点?
- SVN中有类似于VSS中的$NoKeywords: $作用的没?
- 严重: Exception sending context initialized event to listener instance of class
HttpServletRequest request =ServletActionContext.getRequest();
String name=request.getParameter("表单字段名如 name");