您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
1.这个例子是简单的JQuery提交的例子
首先是JSP页面的代码
- <%@ page language="java" contentType="text/html; charset=utf-8"
- pageEncoding="utf-8"%>
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
- <html>
- <head>
- <script type="text/javascript" src="js/jquery-1.4.4.min.js"></script>
- <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
- <title>JQuery测试页面</title>
- <script type="text/javascript">
- function verify(){
- var jqueryObj = $("#username");
- //获取节点的值
- var userName = jqueryObj.val();
- alert(userName);
- $.get("TestAction!test.action?name=" + userName,null,callback);
- }
- function callback(data){
- //alert("服务器返回值:"+data);
- var resultObj = $("#result");
- resultObj.html(data);
- }
- function postsubmit(){
- $.post("TestAction!test.action?name=" + $("#username").val(),null,callback);
- }
- function clean(){
- var resultObj = $("#result");
- resultObj.html("");
- }
- </script>
- </head>
- <body>
- <h2>JQuery练习</h2>
- <input id="username" name="username" value="请输入..."></input>
- <input type="button" onclick="verify()" value="确定"/>
- <input type="button" onclick="postsubmit()" value="post提交"/>
- <input type="button" onclick="clean()" value="清除"/>
- <div id="result"/>
- </body>
- </html>
接着是action的代码
- package com.xiaoqiang;
- import java.io.PrintWriter;
- import javax.servlet.http.HttpServletResponse;
- import org.apache.struts2.ServletActionContext;
- import com.opensymphony.xwork2.ActionContext;
- import com.opensymphony.xwork2.ActionSupport;
- public class TestAction extends ActionSupport {
- private String name;
- @Override
- public String execute() throws Exception {
- // TODO Auto-generated method stub
- return "test";
- }
- public void test() throws Exception {
- // TODO Auto-generated method stub
- System.out.println("name:"+new String(name.getBytes("iso-8859-1"),"utf-8"));
- HttpServletResponse httpServletResponse = ServletActionContext.getResponse();
- httpServletResponse.setContentType("text/html;charset=utf-8");
- PrintWriter pw = httpServletResponse.getWriter();
- pw.print("可以注册");
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- }
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。