質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Struts 2

Apache Struts 2は、Apache Strutsプロジェクトにて開発されているオープンソースのJavaベースのWebアプリケーションフレームワークです。Sturts1に比べ、設定ファイルの削減、依存性の注入、POJO等の改善がなされています。

Q&A

解決済

1回答

2431閲覧

Struts2.5.20でアクションを呼び出した(アドバイスも受付中)

arufa86

総合スコア19

Java

Javaは、1995年にサン・マイクロシステムズが開発したプログラミング言語です。表記法はC言語に似ていますが、既存のプログラミング言語の短所を踏まえていちから設計されており、最初からオブジェクト指向性を備えてデザインされています。セキュリティ面が強力であることや、ネットワーク環境での利用に向いていることが特徴です。Javaで作られたソフトウェアは基本的にいかなるプラットフォームでも作動します。

Struts 2

Apache Struts 2は、Apache Strutsプロジェクトにて開発されているオープンソースのJavaベースのWebアプリケーションフレームワークです。Sturts1に比べ、設定ファイルの削減、依存性の注入、POJO等の改善がなされています。

0グッド

0クリップ

投稿2019/02/23 00:48

編集2019/02/23 02:23

前提・実現したいこと

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

クラスパス:
後程追記します

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

wwbQzhMkhhgEmhU

2019/02/23 05:33

似たようなことやってる記事を見つけたので、まずはこれの通りにやってください。 https://www.tech-tech.xyz/struts2-hello-world.html そして、ご自分のソースや設定と見比べてください。 それでも動かない場合はまた別途質問をしてください。 何をしたのかも分からない状況で、いきなり動かないので教えてくれ、と丸投げするのはNGです。
arufa86

2019/02/23 14:50

ご指摘ありがとうございます。 貼っていただいたサイトを参考につつ、 再度自分でも調べながらやってみます。
guest

回答1

0

ベストアンサー

Struts2のActionクラスは、ActionSupportの継承が必須です。

投稿2019/03/01 16:07

A-pZ

総合スコア12011

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

arufa86

2019/03/02 02:29

解決しました! ありがとうございました!
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問