メモ
遷移予定のページがない場合デフォルトのページに飛ばす設定だけどもっといい方法ないのかな?
IndexAction
import java.io.File;
import java.io.IOException;
import java.rmi.ServerException;
import java.sql.SQLException;
import java.util.ResourceBundle;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.ExceptionMapping;
import org.apache.struts2.convention.annotation.ExceptionMappings;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.InterceptorRefs;
import org.apache.struts2.convention.annotation.Result;
/**
* デバッグ用.
* @author asahina_dev
*
*/
@SuppressWarnings("serial")
@Actions({
@Action(value = "user_*_index",
results = {
@Result(
name = "success",
location = "%{pageId}/index.jsp"),
@Result(
name = "input",
location = "%{pageId}/index.jsp"),
@Result(
name = "defaultAction",
type = "chain",
location = "index"),
},
params = {
"pageId", "{1}"
}),
@Action(value = "index",
results = {
@Result(
name = "success",
location = "index.jsp"),
@Result(
name = "input",
location = "index.jsp"),
}),
})
@InterceptorRefs({
@InterceptorRef("defaultStack"),
@InterceptorRef("debugging")
})
@ExceptionMappings({
@ExceptionMapping(
exception = "java.lang.Exception",
result = "exception"
),
})
public class IndexAction extends BaseAction<IndexModel> {
/**
* デバッグ用.
*
*/
public IndexAction() {
super(new IndexModel());
}
@Override
public String execute() throws IOException, SQLException, ServerException {
System.out.println("index");
ResourceBundle property = ResourceBundle.getBundle("struts");
String resultPath = property.getString("struts.convention.result.path");
String classes = getClass().getResource("/").getFile();
File root = new File(classes, "../../" + resultPath);
File page = new File(root, "debug/" + model.pageId + "/index.jsp");
if (!page.exists()) {
return "defaultAction";
}
return super.execute();
}
}