使用Struts 2.2.x的简单JSON示例? [英] Simple JSON example using Struts 2.2.x?

查看:127
本文介绍了使用Struts 2.2.x的简单JSON示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Struts 2.2.1.1 时无法获得JSON结果.

I’m having trouble getting JSON results working with Struts 2.2.1.1.

有没有人有一个简单的工作示例,该示例使用 Struts 2.2.1.1 将JSON结果返回到JSP,并准备以 dynamic的形式在 Eclipse 中运行网络项目?

Does anyone have a simple working example that returns a JSON result to a JSP using Struts 2.2.1.1 and is ready to run in Eclipse as a dynamic web project?

请包括struts.xml,操作类和JSP代码.另外,请注意依赖项.谢谢.

Please include the struts.xml, action class and JSP code. Also, note dependencies. Thank you.

推荐答案

此处介绍了如何使用Struts 2 jQuery插件创建简单的JSON示例.

Here’s how to create a simple JSON example using the Struts 2 jQuery plugin.

  1. 转到 Struts2 jQuery插件展示
  2. 导航到 Ajax表单>按钮集/复选框
  3. 查看从AJAX JSON结果填充的 Buttonset的代码.这是我选择创建一个简单示例的代码.
  4. 在Eclipse中创建动态Web项目
  5. 创建一个Java包并将其命名为 test .
  6. 下载 Struts 2 jQuery插件展示源( struts2-jquery-showcase-xxx-sources.jar )并提取JAR文件.
  7. Echo.javaJsonSample.javaListValue.java导入到 test 程序包中,并通过快速修复将代码移动到程序包中.
  8. Echo.javaJsonSample.java中的类注释更改为@ ParentPackage(value = "test")
  9. 除了标准的Struts 2库外,请确保 struts2-json-plugin-xxxjar struts2-jquery-plugin-xxxjar struts2-convention-plugin-xxxjar 文件在您的类路径中.
  10. 创建一个struts.xml文件并添加以下XML:

  1. Go to Struts2 jQuery Plugin Showcase
  2. Navigate to Ajax Forms > Buttonset / Checkboxes
  3. Review the code for Buttonset that was populated from AJAX JSON Result. This is code I selected to create a simple example.
  4. Create dynamic web project in Eclipse
  5. Create a Java package and name it test.
  6. Download the Struts 2 jQuery plugin showcase source (struts2-jquery-showcase-x.x.x-sources.jar) and extract the JAR file.
  7. Import Echo.java, JsonSample.java, and ListValue.java into the test package and move the code into the package with quick fix.
  8. Change the class annotation in Echo.java and JsonSample.java to @ParentPackage(value = "test")
  9. In addition to the standard Struts 2 libraries, ensure that the struts2-json-plugin-x.x.x.jar, struts2-jquery-plugin-x.x.x.jar, and struts2-convention-plugin-x.x.x.jar files are in your classpath.
  10. Create a struts.xml file and add the following XML:

<struts>
    <constant name="struts.devMode" value="true" />
    <constant name="struts.convention.action.packages" value="test" />
    <package name="test" extends="json-default" namespace="/">
    </package>
</struts>

  • 创建一个index.jsp文件并插入以下代码:

  • Create an index.jsp file and insert the following code:

    <s:form id="form2" action="echo" theme="xhtml">
     <s:url id="remoteurl" action="jsonsample" />
    <sj:checkboxlist href="%{remoteurl}" id="remoteCheckboxlist" name="echo"  list="languageList" label="Language" />
    <sj:submit targets="formResult" value="AJAX Submit" indicator="indicator" button="true"/>
    </s:form>
    

  • 运行示例.

  • Run the example.

    这篇关于使用Struts 2.2.x的简单JSON示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆