博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
struts系列:返回json格式的响应
阅读量:6915 次
发布时间:2019-06-27

本文共 1178 字,大约阅读时间需要 3 分钟。

一、增加依赖库

// https://mvnrepository.com/artifact/org.apache.struts/struts2-json-plugincompile group: 'org.apache.struts', name: 'struts2-json-plugin', version: '2.5.16'

二、struts.xml配置示例

  
/pages/hello.jsp
jsonData
true

三、action部分

private String name;                   //GET请求参数    private String password;               //GET请求参数    private Map
jsonData; //响应的数据结构(由strut-json插件自动转换成json格式) public String execute() { logger.debug("name=" + name); logger.debug("pwd=" + password); if ("lings".equals(name)) { return SUCCESS; } else { jsonData = new HashMap
(); jsonData.put("user", name); jsonData.put("password", password); return "errLogin"; } } //略去getter和setter方法

四、请求示例

http://localhost:8080/strutsDemo/hello?name=lings&password=123

五、响应示例

{
"password":"123","user":"lings"}

 

转载于:https://www.cnblogs.com/yoyotl/p/9325976.html

你可能感兴趣的文章
saltstack搭建集群3
查看>>
Python学习(13)--Lambda表达式和switch语句的实现
查看>>
the vmrc console has disconnected attempting to reconnect
查看>>
配置bind主域名服务器
查看>>
DeepMind让AI系统拥有记忆,教机器学习系统举一反三打游戏
查看>>
WordPress用户登录后根据不同的角色跳转到不同的页面处理
查看>>
利用autobench测试web服务器极限并发数
查看>>
视图和模型变换
查看>>
Matlab绘图控制命令
查看>>
C#实现CAD数据转shape或mdb
查看>>
使用MiniProfiler给Asp.net MVC和Entity Framework号脉(附源码)
查看>>
机器学习的算法选择
查看>>
java:正则表达式 --转http://blog.csdn.net/yangjiali014/archive/2007/06/19/1658235.aspx
查看>>
猜想:一组勾股数a^2+b^2=c^2中,a,b之一必为4的倍数。
查看>>
RVM 安装与使用帮助
查看>>
django学习笔记(4)
查看>>
Hadoop集群(第3期)_VSFTP安装配置
查看>>
centos7查看系统版本,查看机器位数x86-64
查看>>
Android GIS开发系列-- 入门季(6)GraphicsLayer添加文字与图片标签
查看>>
.Net处理Oracle中Clob类型字段总结
查看>>