struts 2 convention 플러그 인의 사용 (1)
struts 2 convention 플러그 인 에 관 한 글 은 인터넷 상에 서 아직 매우 적 습 니 다. 오늘 연 구 했 습 니 다.
공식 문서 http://cwiki.apache.org/WW/convention-plugin.html
첨부 파일 내 소스 환경 (다운로드 페이지 끝까지)
Dynamic Web Project
eclipse3.3
jdk1.6
tomcat6
필요 jar 목록
commons-fileupload-1.2.1.jar
commons-logging-1.0.4.jar
freemarker-2.3.13.jar
ognl-2.6.11.jar
struts2-convention-plugin-2.1.6.jar
struts2-core-2.1.6.jar
xwork-2.1.2.jar
Web. xml 관건 부분
<!-- ============================ struts2 ============================ -->
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
struts 2. 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>
<!-- //-->
<!--++++++++++++++++++++++++++++++++++++++++++++++++ -->
<constant name="struts.devMode" value="true" />
<!-- -->
<constant name="struts.i18n.reload" value="true" />
<!-- -->
<constant name="struts.configuration.xml.reload" value="true" />
<!-- convention -->
<constant name="struts.convention.classes.reload" value="true" />
<!--++++++++++++++++++++++++++++++++++++++++++++++++ -->
<!-- -->
<constant name="struts.ui.theme" value="simple" />
<!-- -->
<constant name="struts.locale" value="zh_CN" />
<!-- -->
<constant name="struts.i18n.encoding" value="UTF-8" />
<!-- -->
<constant name="struts.action.extension" value="action,do,jsp" />
<!-- -->
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<!-- Struts 2 Action -->
<constant name="struts.enable.SlashesInActionNames" value="false" />
<!-- -->
<constant name="struts.convention.result.path" value="/"/>
<!-- action -->
<constant name="struts.convention.action.suffix" value="Action"/>
<!-- -->
<constant name="struts.convention.action.name.lowercase" value="true"/>
<!-- action 。 HelloWorldAction。 ,actionName hello_world。 -->
<constant name="struts.convention.action.name.separator" value="_"/>
<!-- -->
<constant name="struts.convention.action.disableScanning" value="false"/>
<!-- -->
<constant name="struts.convention.default.parent.package" value="default"/>
<!-- 。 action 。basePackage , , 。locators locators.basePackage 。 -->
<constant name="struts.convention.package.locators" value="actions"/>
<!-- -->
<constant name="struts.convention.package.locators.disable" value="false"/>
<!-- -->
<constant name="struts.convention.package.locators.basePackage" value="com.sunflower.actions"/>
<!-- -->
<constant name="struts.convention.exclude.packages" value="org.apache.struts.*,org.apache.struts2.*,org.springframework.web.struts.*,org.springframework.web.struts2.*,org.hibernate.*"/>
<!-- -->
<!-- jar, , action jar -->
<constant name="struts.convention.action.includeJars" value="" />
<!-- -->
<constant name="struts.convention.relative.result.types" value="dispatcher,freemarker"/>
<!--
true, action /login, HelloWorldAction。result success, /WEB-INF/pages/login/hello_world.jsp( hello_world_success.jsp , “_” <constant name="struts.convention.action.name.separator" value="_"/> )。 action result “error”, /WEB-INF/pages /login/hello_world_error.jsp。
false, action /login, HelloWorldAction。result success, /WEB- INF/pages/login/hello_world/index.jsp( success.jsp )。 action result “error”, /WEB-INF/pages /login/hello_world/error.jsp。
-->
<constant name="struts.convention.result.flatLayout" value="true"/>
<constant name="struts.convention.action.mapAllMatches" value="false"/>
<!-- action -->
<constant name="struts.convention.action.checkImplementsAction" value="true"/>
<constant name="struts.mapper.alwaysSelectFullNamespace" value="false"/>
<constant name="struts.convention.redirect.to.slash" value="true"/>
<package name="default" extends="struts-default">
<interceptors>
<interceptor-stack name="defaultStack">
<interceptor-ref name="exception" />
<interceptor-ref name="servletConfig" />
<interceptor-ref name="actionMappingParams" />
<interceptor-ref name="staticParams" />
<interceptor-ref name="params" />
</interceptor-stack>
</interceptors>
</package>
</struts>
Navigator 액 션 소스 코드
package com.sunflower.actions;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Actions;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import com.opensymphony.xwork2.ActionContext;
@Results( {
@Result(name = "next", location = "/next.jsp", type = "dispatcher"),
@Result(name = "error", location = "error.jsp", type = "dispatcher"),
@Result(name = "redirectAction", location = "./child/child", type = "redirectAction"),
@Result(name = "redirect", location = "http://sunflowers.iteye.com", type = "redirect") })
public class NavigatorAction {
private String actionName;
public void setActionName(String actionName) {
this.actionName = actionName;
}
public String index() {
outputMsg("method:index");
return "next";
}
public String execute() {
outputMsg("method:execute,no index method");
return "next";
}
public String error() {
try {
throw new Exception();
} catch (Exception e) {
outputMsg(e);
return "error";
}
}
public String redirect() {
System.out.println(" :rediret");
return "redirect";
}
public String redirectAction() {
outputMsg("navigatorAction , navigator!redirectAction.action, ");
return "redirectAction";
}
@Action(value = "/test/childTest")
public String action() {
outputMsg("@action ---method:action");
return "next";
}
@Actions( { @Action(value = "/test/action1"),
@Action(value = "/test/action2") })
public String actions() {
outputMsg("@actions ---method:actions,action=" + actionName);
return "next";
}
private void outputMsg(Object msg) {
System.out.println(msg);
ActionContext.getContext().put("msg", msg);
}
}
ChildAction 소스 코드
package com.sunflower.actions.child;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
@Results( {
@Result(name = "next", location = "next.jsp", type = "dispatcher")})
public class ChildAction {
public String execute() {
System.out.println("childAction ");
return "next";
}
}
index. jsp 원본 코드
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>struts2 convention </title>
<style>
* {
line-height: 2em;
}
a:visited,a:hover,a:active,a:link {
color: #00f;
}
</style>
</head>
<body>
Action
<ul class="horizontal">
<li>com.sunflower.actions.NavigatorAction</li>
<li>com.sunflower.actions.child.ChildAction</li>
</ul>
<ul class="horizontal">
<li>error.jsp</li>
<li>index.jsp</li>
<li>next.jsp</li>
<li>child/next.jsp</li>
</ul>
<ul>
<li> : action execute index<br />
url:navigator.action <br />
:dispatcher <br />
:execute index <br />
<a href="./navigator.action"> </a></li>
<li> : <br />
url:navigator!redirect.action <br />
:redirect( ServletRedirectResult.class) <br />
:redirect <br />
<a href="./navigator!redirect.action"> </a></li>
<li> : redirectAction、basePackage action 、 <br />
url:navigator!redirectAction.action <br />
:redirectAction ( ServeltActionRedirectResult.class) <br />
:redirectAction <br />
location:child/child(basePackage=com.sunflower.actions,this package=com.sunflower.actions.child)
<br />
<font color="red"> </font><br />
1:ChildAction execute location="next.jsp", next.jsp /child/next.jsp
<br />
2: redirectAction msg , msg <br />
<a href="./navigator!redirectAction.action"> action</a></li>
<li> : <br />
url:navigator!error.action <br />
<a href="./navigator!error.action"> </a></li>
<li> :@Action Result location <br />
@Action(value="/test/childTest") <br />
url:/test/childTest.action <br />
<font color="red"> </font>: NavigatorAction <br />
<a href="./test/childTest.action">next.jsp </a></li>
<li> :@Actions <br />
@Actions({ @Action(value="/test/actions1"),
@Action(value="/test/actions2") })<br />
<br />
url:/test/action1.action <br />
url:/test/action2.action <br />
<font color="red"> </font>: NavigatorAction <br />
<a href="./test/action1.action?actionName=action1">action1</a> <a
href="./test/action2.action?actionName=action2">action2</a></li>
</ul>
</body>
</html>
next. jsp 소스 코드
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title><style>
*{
line-height:3em;
}
</style>
</head>
<body>
<h1>struts2 convention </h1>
<br />
${msg}
<br />
<a href="#" onclick="window.history.go(-1);return false;"> </a>
</body>
</html>
child / next. jsp 원본 코드
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title><style>
*{
line-height:3em;
}
</style>
</head>
<body>
child/next.jsp:{msg}
</body>
</html>
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
자바 파일 압축 및 압축 풀기파일 의 간단 한 압축 과 압축 해 제 를 실현 하 였 다.주요 테스트 용 에는 급 하 게 쓸 수 있 는 부분 이 있 으 니 불편 한 점 이 있 으 면 아낌없이 가르쳐 주 십시오. 1. 중국어 문 제 를 해 결 했 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.