在struts中,通过Ajax,利用jQuery,将action中的数据转到前台页面
来源:互联网 发布:java 敏捷开发框架 编辑:程序博客网 时间:2024/06/05 20:16
第一步、配置Struts(注意,返回的数据类型为json数据,)
<?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> <!--声明包--> </package> <package name="json" extends="json-default" namespace="/"> <action name="UserTestAction" class="com.aisino.development.UserTestAction" method="Test"> <result name="success" type="json">
<param name="root">name</param> //默认name为root </result> </action> </package> </struts>第二步、配置web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app version="2.5" <span style="white-space:pre"></span>xmlns="http://java.sun.com/xml/ns/javaee" <span style="white-space:pre"></span>xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <span style="white-space:pre"></span>xsi:schemaLocation="http://java.sun.com/xml/ns/javaee <span style="white-space:pre"></span>http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><span style="white-space:pre"></span><filter> <!--配置struts2过滤器 --><span style="white-space:pre"></span><!--过滤器名称 --><span style="white-space:pre"></span><filter-name>struts2</filter-name><span style="white-space:pre"></span><!--过滤器类 --><span style="white-space:pre"></span><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter><filter-mapping><span style="white-space:pre"></span><filter-name>struts2</filter-name> <!--过滤器名称 --><span style="white-space:pre"></span><url-pattern>/*</url-pattern> <!--过滤器映射 --></filter-mapping><welcome-file-list> <welcome-file>Test.jsp</welcome-file></welcome-file-list></web-app>3、第三步、配置jQuery
在WebRoot下面新建一个JS文件夹,将jQuery库复制到其中:jquery-1.8.3.min.js
4、写jsp文件,
注意配置jQuery语句
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>jQuery测试</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> </head> //配置jQuery语句 <span style="color:#ff6666;"> </span><span style="font-size:18px;color:#ff0000;"><script src="js/jquery-1.8.3.min.js"></script></span> <script type="text/javascript"> //写一个函数 <span style="font-size:18px;color:#ff0000;">function test(){ $.ajax( {</span>
<span style="font-size:18px;color:#ff0000;"> url:"/Login_Struts_demo1/UserTestAction", //url地址,action地址 type:"get", //get/post两种类型,一般用get dataType:"json", //返回前台的数据类型 success:function(data) //访问成功后执行弹窗,data为访问的url地址中action返回的数据 { alert(data); } } ); }</span> </script> <body> <center> <input type="button" value="jQuery" onclick="test()"> </center> </body></html>
5、第五步,写Action
package com.aisino.development;import java.util.ArrayList;import java.util.List;import com.opensymphony.xwork2.ActionSupport;public class UserTestAction extends ActionSupport {public String Test(){String name="张三";return SUCCESS;}}
6、通过网页就可以测试该程序了,作为一个初学者,写的也是基础,希望能到需要的人
1 0
- 在struts中,通过Ajax,利用jQuery,将action中的数据转到前台页面
- struts:将Action处理后的数据传递给前台jsp页面
- 利用jquery框架中ajax实现前台与struts2中action交互
- 加载页面时,ajax异步请求数据,$.each()遍历数据,通过jQuery将数据html()到dom结构中
- jquery通过ajax在jsp中局部刷新页面
- 在jQuery中利用AJAX加载XML数据并解析
- 在jQuery中利用AJAX加载XML数据并解析
- 在jQuery中利用AJAX加载XML数据并解析
- 在jQuery中利用AJAX加载XML数据并解析
- 在jQuery中利用AJAX加载XML数据并解析
- Struts中利用ajax/jquery页面动态无刷新添加信息
- struts.xml中获得action中的数据
- 在Action中查询出SQL SERVER表的数据,返回一个list。怎么在JSP页面中使用Struts标签,显示出表中的内容?(转)
- ssh 中 jquery ajax 调用action返回的json数据并传递到页面
- SpringMVC中的ModelMap(将后台数据传到前台页面)
- 通过JQuery中的ajax请求数据
- 通过jquery ajax在从服务器获取一个文件的数据,显示到客户端的页面
- 一例解析通过$.ajax()获取后台服务器数据并通过vue渲染在页面中
- 每日小记(16.9.24)
- 值得推荐的C/C++框架和库 (真的很强大)
- 函数方法和用法
- SVN 版本管理:两种开发模式
- 获取WIN7的trustedinstaller权限
- 在struts中,通过Ajax,利用jQuery,将action中的数据转到前台页面
- 在一幅图上叠加第二幅小图作为logo的实现 ,addWeighted和copyTo方法 opencv
- E L 表达式
- [易飞]易飞直接查询卡死(gridviewerC.dll注册卡死)
- iOS10及Xcode8适配
- java javac windows
- SQL LIKE子句
- WebService------Apache CXF
- HDU-2020