1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Struts2でユーザーごとのページ(設定してない場合はデフォルト)

Posted at

メモ

遷移予定のページがない場合デフォルトのページに飛ばす設定だけどもっといい方法ないのかな?

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();
	}
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?