Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 4D3B3200B84 for ; Mon, 5 Sep 2016 10:12:34 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 4A2F2160ABC; Mon, 5 Sep 2016 08:12:34 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 71058160ACB for ; Mon, 5 Sep 2016 10:12:33 +0200 (CEST) Received: (qmail 9941 invoked by uid 500); 5 Sep 2016 08:12:32 -0000 Mailing-List: contact commits-help@struts.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@struts.apache.org Delivered-To: mailing list commits@struts.apache.org Received: (qmail 9921 invoked by uid 99); 5 Sep 2016 08:12:32 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 05 Sep 2016 08:12:32 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 21840E08B8; Mon, 5 Sep 2016 08:12:32 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: lukaszlenart@apache.org To: commits@struts.apache.org Date: Mon, 05 Sep 2016 08:12:32 -0000 Message-Id: <29b1f5b180f84b0581ba9a8802b9ea7e@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] struts-examples git commit: Adds example how to consume JSON archived-at: Mon, 05 Sep 2016 08:12:34 -0000 Repository: struts-examples Updated Branches: refs/heads/master bd7959d98 -> 9d0a2f304 Adds example how to consume JSON Project: http://git-wip-us.apache.org/repos/asf/struts-examples/repo Commit: http://git-wip-us.apache.org/repos/asf/struts-examples/commit/b8eb5472 Tree: http://git-wip-us.apache.org/repos/asf/struts-examples/tree/b8eb5472 Diff: http://git-wip-us.apache.org/repos/asf/struts-examples/diff/b8eb5472 Branch: refs/heads/master Commit: b8eb547247389e3a97f0c1629cde6784d595fa03 Parents: bd7959d Author: Lukasz Lenart Authored: Mon Sep 5 10:10:50 2016 +0200 Committer: Lukasz Lenart Committed: Mon Sep 5 10:10:50 2016 +0200 ---------------------------------------------------------------------- json/src/main/java/org/demo/ConsumeAction.java | 12 ++++- json/src/main/resources/struts.xml | 12 +++-- json/src/main/webapp/WEB-INF/index.jsp | 13 +++++ json/src/main/webapp/consume.html | 53 +++++++++++++++++++++ json/src/main/webapp/index.html | 10 ---- 5 files changed, 86 insertions(+), 14 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/struts-examples/blob/b8eb5472/json/src/main/java/org/demo/ConsumeAction.java ---------------------------------------------------------------------- diff --git a/json/src/main/java/org/demo/ConsumeAction.java b/json/src/main/java/org/demo/ConsumeAction.java index c142581..e7e6804 100644 --- a/json/src/main/java/org/demo/ConsumeAction.java +++ b/json/src/main/java/org/demo/ConsumeAction.java @@ -22,12 +22,19 @@ package org.demo; import com.opensymphony.xwork2.ActionSupport; +import org.apache.struts2.interceptor.ServletRequestAware; -public class ConsumeAction extends ActionSupport { +import javax.servlet.http.HttpServletRequest; + +public class ConsumeAction extends ActionSupport implements ServletRequestAware { private MyBean bean = new MyBean(); + private boolean responseAsJson = true; public String execute() throws Exception { + if (responseAsJson) { + return "JSON"; + } return SUCCESS; } @@ -35,4 +42,7 @@ public class ConsumeAction extends ActionSupport { return bean; } + public void setServletRequest(HttpServletRequest request) { + responseAsJson = request.getHeader("Accept").contains("application/json"); + } } \ No newline at end of file http://git-wip-us.apache.org/repos/asf/struts-examples/blob/b8eb5472/json/src/main/resources/struts.xml ---------------------------------------------------------------------- diff --git a/json/src/main/resources/struts.xml b/json/src/main/resources/struts.xml index b82521b..75b1d92 100644 --- a/json/src/main/resources/struts.xml +++ b/json/src/main/resources/struts.xml @@ -8,7 +8,11 @@ - + + + + /WEB-INF/index.jsp + @@ -20,9 +24,11 @@ bean - application/json - WEB-INF/result.jsp + /WEB-INF/result.jsp + + bean + http://git-wip-us.apache.org/repos/asf/struts-examples/blob/b8eb5472/json/src/main/webapp/WEB-INF/index.jsp ---------------------------------------------------------------------- diff --git a/json/src/main/webapp/WEB-INF/index.jsp b/json/src/main/webapp/WEB-INF/index.jsp new file mode 100644 index 0000000..651f3f1 --- /dev/null +++ b/json/src/main/webapp/WEB-INF/index.jsp @@ -0,0 +1,13 @@ +<%@ page contentType="text/html; charset=UTF-8" %> +<%@ taglib prefix="s" uri="/struts-tags" %> + + + JSON Result + + + +Produce JSON +Consume JSON + + + \ No newline at end of file http://git-wip-us.apache.org/repos/asf/struts-examples/blob/b8eb5472/json/src/main/webapp/consume.html ---------------------------------------------------------------------- diff --git a/json/src/main/webapp/consume.html b/json/src/main/webapp/consume.html new file mode 100644 index 0000000..6f19177 --- /dev/null +++ b/json/src/main/webapp/consume.html @@ -0,0 +1,53 @@ + + + + How to consume a JSON request + + + + + + +
+
Counter:
+
Name 1:
+
Name 2:
+ + +
+ + + + http://git-wip-us.apache.org/repos/asf/struts-examples/blob/b8eb5472/json/src/main/webapp/index.html ---------------------------------------------------------------------- diff --git a/json/src/main/webapp/index.html b/json/src/main/webapp/index.html deleted file mode 100644 index dc2bbd0..0000000 --- a/json/src/main/webapp/index.html +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - -

Loading ...

- -