前提・実現したいこと
Struts2でHelloアクションを呼び出したい。
発生している問題・エラーメッセージ
HTTPステータス 404 - There is no Action mapped for namespace [/] and action name [Hello] associated with context path [/msample].
該当のソースコード
part1.Hello.java (アクションクラス)
Java
1package part1; 2 3public class Hello { 4private String replyMsg; 5 6public String getReplyMsg() { 7 return replyMsg; 8} 9 10public void setReplyMsg(String replyMsg) { 11 this.replyMsg = replyMsg; 12} 13 14public String execute() throws Exception { 15 this.setReplyMsg( "Struts 2の世界へようこそ" ); 16 return "success"; 17} 18} 19
index.jsp (呼び出すHelloアクションがある)
Jsp
1<%@ page language="java" contentType="text/html; charset=UTF-8" 2 pageEncoding="UTF-8"%> 3<%@ taglib prefix="s" uri="/struts-tags" %> 4<!DOCTYPE html PUBLIC 5 "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> 6<html> 7<head> 8<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 9<title>Hello!Project</title> 10</head> 11<body> 12<a href="Hello.action">こんちには </a> 13<br /> 14<s:property value="replyMsg"/> 15</body> 16</html>
web.xml
xml
1<!DOCTYPE web-app PUBLIC 2 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" 3 "http://java.sun.com/dtd/web-app_2_3.dtd" > 4 5<web-app> 6 <display-name>Archetype Created Web Application</display-name> 7 8 <filter> 9 <filter-name>struts2</filter-name> 10 <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter 11 </filter-class> 12 </filter> 13 14 <filter-mapping> 15 <filter-name>struts2</filter-name> 16 <url-pattern>/*</url-pattern> 17 </filter-mapping> 18 19 <welcome-file-list> 20 <welcome-file>index.jsp</welcome-file> 21 </welcome-file-list> 22</web-app> 23
struts.xml
xml
1<?xml version="1.0" encoding="UTF-8" ?> 2<!DOCTYPE struts PUBLIC 3 "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 4 "http://struts.apache.org/dtds/struts-2.0.dtd"> 5<struts> 6 <package name="msample" extends="struts-default"> 7 8 <action name="Hello" class="part1.Hello" method="execute"> 9 <result name="success">/index.jsp</result> 10 </action> 11 12 </package> 13</struts>
pom.xml
xml
1<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 2 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 3 <modelVersion>4.0.0</modelVersion> 4 <groupId>com.example.mavensample</groupId> 5 <artifactId>msample</artifactId> 6 <packaging>war</packaging> 7 <version>0.0.1-SNAPSHOT</version> 8 <properties> 9 <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 10 <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> 11 <java-version>1.8</java-version> 12 </properties> 13 <name>msample Maven Webapp</name> 14 <url>http://maven.apache.org</url> 15 <dependencies> 16 <dependency> 17 <groupId>junit</groupId> 18 <artifactId>junit</artifactId> 19 <version>4.12</version> 20 <scope>test</scope> 21 </dependency> 22 23 <dependency> 24 <groupId>javax.servlet</groupId> 25 <artifactId>servlet-api</artifactId> 26 <version>2.5</version> 27 <scope>provided</scope> 28</dependency> 29<dependency> 30 <groupId>org.apache.poi</groupId> 31 <artifactId>poi</artifactId> 32 <version>3.17</version> 33</dependency> 34<dependency> 35 <groupId>org.apache.struts</groupId> 36 <artifactId>struts2-core</artifactId> 37 <version>2.5.20</version> 38</dependency> 39<dependency> 40 <groupId>org.apache.struts</groupId> 41 <artifactId>struts2-java8-support-plugin</artifactId> 42 <version>2.5.2</version> 43</dependency> 44<dependency> 45 <groupId>org.ow2.asm</groupId> 46 <artifactId>asm</artifactId> 47 <version>5.0.2</version> 48</dependency> 49<dependency> 50 <groupId>org.apache.logging.log4j</groupId> 51 <artifactId>log4j-core</artifactId> 52 <version>2.11.2</version> 53</dependency> 54 55 56 </dependencies> 57 <build> 58 <finalName>msample</finalName> 59 </build> 60</project> 61
試したこと
アクションクラスの移動
補足情報(FW/ツールのバージョンなど)
Tomcat 8.0.32
Struts2.5.20
Java8
Log4j2
クラスパス:
後程追記します
回答1件
あなたの回答
tips
プレビュー