日期:2014-05-16  浏览次数:20348 次

strust 2.18 应用json 学习

1. ?struts2 必需包.

2.

json-lib-2.2-jdk15.jar

?

commons-beanutils.jar,

commons- lang.jar,

ezmorph.jar,

struts2-json.jar

这些包在strust2.18中都有.

?

实例:界面

?

<%@ page language="java" ?pageEncoding="GBK"%>

<%@ taglib prefix="s" uri="/struts-tags"%>

?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

??<head>

?

?? ?<title>My JSP 'index.jsp' starting page</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">

<script type="text/javascript" src="js/jquery-1.4.2.min.js"></script>

<script type="text/javascript" src="js/json2.js"></script>

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->

<script type="text/javascript">

?? $(function(){

?? $("#login").click(function(){

?? login();

??

?? });

??

?? })

?

?? function login(){

?? var url="user_login.action";

?? var name=$("#name").attr("value");

?? var password=$("#password").attr("value");

?? var params={"user.name":name,"user.password":password};

??

?? $.getJSON(url,params,function callback(data){

?? var user=eval("("+data+")");

??

?? $("#result").each(function(){

?? $(this).html('welcome ,'+user.name);

?? });

?? });

??

?? }

?

?</script>

??</head>

?

??<body>&nbsp;?

?? ?This is my JSP page. <br>

?

?? ?<s:actionmessage/>

?

?? ?<form action="" id ="form">

?? ? 用户名:

?? ? <input type="text" name="user.name" id="name">

?? ? <br>

?? ?