実現したいこと
struts2を使ってjson形式の文字列を表示させるだけの簡単なプログラムを作成しようとしています。
ブラウザはIE11です。
発生している問題・エラーメッセージ
しかし、json形式の文字列を表示させようとすると、画面が表示されず、
テキストファイルのダウンロードダイアログが表示されてしまいます。
そのテキストファイルをダウンロードして中身を見てみると
json形式の文字列が入っているのでjson形式に変換するところまでは
できているはずです。
index.jspに表示させるにはどうしたらよろしいでしょうか。
該当のソースコード
【struts.xml】
<?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 name="hello" namespace="/" extends="json-default"> <result-types> <result-type name="json" class="org.apache.struts2.json.JSONResult" /> </result-types> <action name="hello" class="test.actions.HelloAction" method="execute"> <result name="success" type="json">/index.jsp </result> </action> </package> </struts>【index.jsp】
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
【HelloAction.java】
package test.actions;
import java.util.HashMap;
import com.opensymphony.xwork2.ActionSupport;
public class HelloAction extends ActionSupport{
private static final long serialVersionUID = 1L;
private HashMap<String,String> msg;
private String text01;
public HashMap<String,String> getMsg() {
return msg;
}
public void setMsg(HashMap<String,String> msg) {
this.msg = msg;
}
public String getText01() {
return text01;
}
public void setText01(String text01) {
this.text01 = text01;
}
public String execute()
{
HashMap<String,String> map = new HashMap<String,String>();
map.put("english",text01);
map.put("japanese",text01);
setMsg(map);
return "success";
}
}
【API】
asm-5.2
asm-commons-5.2
asm-tree-5.2
commons-fileupload-1.3.3
commons-io-2.5
commons-lang-2.4
commons-lang3-3.6
commons-logging-1.1.3
freemarker-2.3.26-incubating
javassist-3.20.0-GA
log4j-api-2.9.1
ognl-3.1.15
struts2-convention-plugin-2.5.14.1
struts2-core-2.5.14.1
struts2-json-plugin-2.5.14.1
xmlpull-1.1.3.1
xpp3_min-1.1.4c
xstream-1.4.10
補足情報
JDK 1.8.0
tomcat8.0
struts2-2.5