真心求一份Struts2 + JQuery实现ajax方式提交表单的方法!!

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了真心求一份Struts2 + JQuery实现ajax方式提交表单的方法!!相关的知识,希望对你有一定的参考价值。

如果需要插件 麻烦写下名字及简单的用法 谢谢了! !

例子:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<script src="jquery.js"></script>
<script>
function sub()
var value1 = $("#id1").val();
var value2 = $("#id2").val();
if(value1!="" && value2!="")
$.ajax(
url:'a.action',
type:'post',
data:'value1='+value1+'&value2='+value2
//data:value1:value1,value2:value2,
dataType:'text',
success:function(text)
alert(text);

)


</script>
</head>
<body>
<form id="form1" name="form1">
<input type="text" id="id1"/><br />
<input type="text" id="id2"/><br />
<input type="button" value="提交" onclick="sub();"/>
</form>
</body>
</html>

struts.xml:

<action name="a" class="com.test.a.action" method="test">

</action>

a.action:

private String value1;
private String value2;
private String text;

get()...set()...

public void test()throws Exception
//do somethings
HttpServletResponse response = ServletActionContext.getResponse();
response.setContentType("application/json;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
try
PrintWriter pw = response.getWriter();
boolean flag = XXXService(value1,value2);
String text = "";
if(flag)
text = "执行成功!";
else
text = "执行失败!";

pw.write(text);
pw.flush();
catch(Exception e)
e.printStackTrace();
throw new Exception("执行异常!");

参考技术A jQuery的ajax请求很简单。一个方法就搞定了,
$.get(url,"propertyName":propertValue,function(data));
Struts2 + JQuery实现ajax方式提交 ,几分钟就能搞定
参考技术B 需要的话我发一份给你。留下地址。。

求一份python小游戏 游戏简单点 要用graphics做用户界面~ 真心求 感激不尽~ 好的话追加厚礼么么哒

参考技术A #五子棋
import appuifw,e32,key_codes
from graphics import *
def cn(x):return x.decode('utf-8')
def quit(): _quit=1
global running
running=1
def redraw(rect): canvas.blit(img)
def default():
global con,color,font
con="l":15,"x":15,"y":33,"r":13,"n":15
color="bg":0x7777bb,"fg":0x333333,"p1":0x000000,"p2":0xffffff,"w":0xff0000
font=u"Sans MT 936_S60"
def initial():
global img,canvas,con,color,cur_x,cur_y,turn,pos1,pos2,pos
appuifw.app.screen='full'
appuifw.app.body=canvas=appuifw.Canvas()
img=Image.new((240,320))
img.clear(color["bg"])
cur_x=7
cur_y=7
turn=1
pos1=[]
pos2=[]
pos=[]
for i in range(con["n"]*con["n"]):
pos.append(0)
def paint_back():
global img,color,font
#img.text((90,25),cn('欢乐五子棋'),color["fg"],font)
for i in range(con["x"],con["x"]+con["l"]*con["n"]-1,con["l"]):
img.line((i,con["y"],i,con["y"]+con["l"]*(con["n"]-1)),color["fg"])
for i in range(con["y"],con["y"]+con["l"]*con["n"]-1,con["l"]):
img.line((con["x"],i,con["x"]+con["l"]*(con["n"]-1),i),color["fg"])
img.text((40,270),cn('玩家1'),color["p1"],font)
img.text((160,270),cn('玩家2'),color["p2"],font)
img.point((90,263),color["p1"],width=con["r"],fill=color["p1"])
img.point((144,263),color["p2"],width=con["r"],fill=color["p2"])

def paint_cur(x,y,sh):
global img,con,color,pos1,pos2,running
if running<>1:return
ax=con["x"]+con["l"]*x
ay=con["y"]+con["l"]*y
b=con["l"]/2
if sh<>0:
c=color["p"+str(sh)]
if rp((x,y))<>0:
c=color["w"]
if sh==0:
c=color["bg"]
img.line((ax-b,ay-2,ax-b,ay-b,ax-2,ay-b),c)
img.line((ax-b,ay+2,ax-b,ay+b,ax-2,ay+b),c)
img.line((ax+b,ay-2,ax+b,ay-b,ax+2,ay-b),c)
img.line((ax+b,ay+2,ax+b,ay+b,ax+2,ay+b),c)
redraw(())
def paint_q(x,y,z):
global img,con,color
ax=con["x"]+con["l"]*x
ay=con["y"]+con["l"]*y
b=con["l"]/2
if z==0:
c=color["bg"]
else:
c=color["p"+str(z)]
img.point((ax,ay),c,width=con["r"],fill=c)
redraw(())
if z==0:
img.line((ax-b,ay,ax+b,ay),c)
img.line((ax,ay-b,ax,ay+b),c)

def k_up():
global cur_x,cur_y,con,turn
paint_cur(cur_x,cur_y,0)
cur_y=cur_y-1
if cur_y==-1:
cur_y=con["n"]-1
paint_cur(cur_x,cur_y,turn)
def k_down():
global cur_x,cur_y,con,turn
paint_cur(cur_x,cur_y,0)
cur_y=cur_y+1
if cur_y==con["n"]:
cur_y=0
paint_cur(cur_x,cur_y,turn)
def k_left():
global cur_x,cur_y,con,turn
paint_cur(cur_x,cur_y,0)
cur_x=cur_x-1
if cur_x==-1:
cur_x=con["n"]-1
paint_cur(cur_x,cur_y,turn)
def k_right():
global cur_x,cur_y,con,turn
paint_cur(cur_x,cur_y,0)
cur_x=cur_x+1
if cur_x==con["n"]:
cur_x=0
paint_cur(cur_x,cur_y,turn)
def rp(x):
global con,pos
if (x[0]<0 or x[0]>=con["n"] or x[1]<0 or x[1]>=con["n"]):return 0
#print x,pos[x[0]*con["n"]+x[1]]
return pos[x[0]*con["n"]+x[1]]
def wp(x,y):
global con,pos
pos[x[0]*con["n"]+x[1]]=y

def win():
for i in pos1:
k=0
for j in range(0,6):
if rp((i[0]+j,i[1]))==1:
k=k+1
else:
break
if k>=5:
return 1
k=0
for j in range(0,6):
if rp((i[0],i[1]+j))==1:
k=k+1
else:
break
if k>=5:
return 1
k=0
for j in range(0,6):
if rp((i[0]+j,i[1]+j))==1:
k=k+1
else:
break
if k>=5:
return 1
k=0
for j in range(0,6):
if rp((i[0]+j,i[1]-j))==1:
k=k+1
else:
break
if k>=5:
return 1
for i in pos2:
k=0
for j in range(0,6):
if rp((i[0]+j,i[1]))==2:
k=k+1
else:
break
if k>=5:
return 2
k=0
for j in range(0,6):
if rp((i[0],i[1]+j))==2:
k=k+1
else:
break
if k>=5:
return 2
k=0
for j in range(0,6):
if rp((i[0]+j,i[1]+j))==2:
k=k+1
else:
break
if k>=5:
return 2
k=0
for j in range(0,6):
if rp((i[0]+j,i[1]-j))==2:
k=k+1
else:
break
if k>=5:
return 2
return 0

def k_enter():
global cur_x,cur_y,turn,pos1,pos2,con,color,font,running
if running<>1:return
if rp((cur_x,cur_y))==0:
if turn==1:
pos1.append((cur_x,cur_y))
img.rectangle((35,255,100,272),color["bg"])
img.rectangle((135,255,200,272),color["p2"])
if turn==2:
pos2.append((cur_x,cur_y))
img.rectangle((35,255,100,272),color["p1"])
img.rectangle((135,255,200,272),color["bg"])
paint_q(cur_x,cur_y,turn)
wp((cur_x,cur_y),turn)
if win()<>0:
#img.text((80,300),cn('玩家')+str(turn)+cn("获胜!"),color["fg"],font)
img.rectangle((35,255,100,272),color["bg"])
img.rectangle((135,255,200,272),color["bg"])
paint_cur(cur_x,cur_y,0)
running=2
turn=3-turn
paint_cur(cur_x,cur_y,turn)
def bindkey():
canvas.bind(key_codes.EKeyUpArrow, k_up)
canvas.bind(key_codes.EKeyDownArrow,k_down)
canvas.bind(key_codes.EKeyLeftArrow, k_left)
canvas.bind(key_codes.EKeyRightArrow,k_right)
canvas.bind(key_codes.EKeySelect,k_enter)
default()
initial()
paint_back()
paint_cur(cur_x,cur_y,1)
img.rectangle((35,255,100,272),color["p1"])
bindkey()
redraw(())
appuifw.app.exit_key_handler = quit()
_quit=0
while (1-_quit):
e32.ao_sleep(0.2)
redraw(())追问

除了五子棋还有别的么 最好能发我py文件 谢谢啊

以上是关于真心求一份Struts2 + JQuery实现ajax方式提交表单的方法!!的主要内容,如果未能解决你的问题,请参考以下文章

Struts2+Jquery实现ajax并返回json类型数据

求一份Cadence学习报告

求一份sqlyog中文破解版

跪求一份RAD Studio 10 Seattle破解版,找了好久了。

100分 求一份电脑专用的英语单词(中英对照表)

100分 求一份电脑专用的英语单词(中英对照表)