2010-08-03 11 views
2

안녕하세요 저는 Struts 2 및 모든 Java 웹 개발에 익숙하지 않습니다. 기본 struts2 응용 프로그램을 maven으로 만든 다음 struts2-rest-plugin을 추가하여 프로젝트를 빌드했습니다.Struts 2 + Maven + Struts 2 Rest Plugin 도움말

의 web.xml :

<?xml version="1.0" encoding="UTF-8"?> 
<web-app id="starter" version="2.4" 
     xmlns="http://java.sun.com/xml/ns/j2ee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 

<display-name>Struts 2 - Maven Archetype - Starter</display-name> 

<context-param> 
    <param-name>contextConfigLocation</param-name> 
    <param-value>classpath*:applicationContext*.xml</param-value> 
</context-param> 

<!-- Filters --> 
    <filter> 
     <filter-name>action2</filter-name> 
     <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> 
     <!-- filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class--> 
    </filter> 

    <filter-mapping> 
     <filter-name>action2</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 

<!-- Listeners --> 
<listener> 
     <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> 
    </listener> 

    <!-- Welcome file lists --> 
    <welcome-file-list> 
     <welcome-file>index.jsp</welcome-file> 
     <welcome-file>default.jsp</welcome-file> 
     <welcome-file>index.html</welcome-file> 
    </welcome-file-list> 

</web-app> 

struts.xml

<?xml version="1.0" encoding="UTF-8"?> 
<project> 
<modelVersion>4.0.0</modelVersion> 
<groupId>tutorial</groupId> 
<artifactId>tutorial</artifactId> 
<packaging>war</packaging> 
<version>0.1</version> 
<name>Struts 2 Starter</name> 
<url>http://www.myComp.com</url> 
<description>Struts 2 Starter</description> 

<dependencies> 
    <!-- Junit --> 
    <dependency> 
    <groupId>junit</groupId> 
    <artifactId>junit</artifactId> 
    <version>3.8.1</version> 
    <scope>test</scope> 
    </dependency> 

    <!-- Struts 2 --> 
    <dependency> 
      <groupId>org.apache.struts</groupId> 
      <artifactId>struts2-core</artifactId> 
      <version>2.1.6</version> 
     </dependency> 
     <dependency> 
      <groupId>org.apache.struts</groupId> 
      <artifactId>struts2-spring-plugin</artifactId> 
      <version>2.1.6</version> 
     </dependency> 
     <dependency> 
     <groupId>org.apache.struts</groupId> 
     <artifactId>struts2-convention-plugin</artifactId> 
     <version>2.1.6</version> 
     </dependency> 
     <dependency> 
     <groupId>org.apache.struts</groupId> 
     <artifactId>struts2-rest-plugin</artifactId> 
     <version>2.1.6</version> 
     </dependency> 


    <!-- Servlet & Jsp --> 
    <dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>servlet-api</artifactId> 
    <version>2.4</version> 
    <scope>provided</scope> 
    </dependency> 
    <dependency> 
    <groupId>javax.servlet</groupId> 
    <artifactId>jsp-api</artifactId> 
    <version>2.0</version> 
    <scope>provided</scope> 
    </dependency> 

    <!-- Jakarta Commons --> 
    <dependency> 
    <groupId>commons-fileupload</groupId> 
    <artifactId>commons-fileupload</artifactId> 
    <version>1.1.1</version> 
    </dependency> 

    <!-- Dwr --> 
    <dependency> 
    <groupId>uk.ltd.getahead</groupId> 
    <artifactId>dwr</artifactId> 
    <version>1.1-beta-3</version> 
    </dependency> 
    </dependencies> 

    <build> 
     <finalName>tutorial</finalName> 
    <plugins> 
     <plugin> 
       <artifactId>maven-compiler-plugin</artifactId> 
       <configuration> 
        <source>1.5</source> 
        <target>1.5</target> 
       </configuration> 
      </plugin> 
     <plugin> 
     <groupId>org.mortbay.jetty</groupId> 
     <artifactId>maven-jetty-plugin</artifactId> 
     <version>6.1.5</version> 
     <configuration> 
     <scanIntervalSeconds>10</scanIntervalSeconds> 
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 
</project> 

은 web.xml과 struts.xml은 다음과 같습니다 : 여기의 pom.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.convention.action.suffix" value="Controller"/> 
<constant name="struts.convention.action.mapAllMatches" value="true"/> 
<constant name="struts.convention.default.parent.package" value="rest-default"/> 
<constant name="struts.convention.package.locators" value="example"/> 

</struts> 

이제패키지가 있습니다. 클래스 OrdersController.java 인(struts2-rest-showcase 예제에서 가져옴). mvn 부두가 실행 중임 : 실행 및 실행 URL : http://localhost:8080/tutorial/orders/ 오류 404 발생;

내가 뭘하고 있는거야?

+0

: (모든 것을 시도한 적이 있습니까? – MaX

답변

1

나는 친구들에게 문제를 발견했습니다. 기본적으로 받는다는는 struts.properties 파일을 생성하고이 두 라인은 문제가 있습니다 :

struts.mapper.class = org.apache.struts2.dispatcher.mapper.DefaultActionMapper struts.action.extension = 액션

코멘트 그들과 XML은 효과적 일 것입니다 (이야기의 나머지 부분을 조사하십시오)