|
解凍するファイル
C:\Users\(ユーザ名)\Downloads\struts-7.0.0-all.zip 解凍するとできるフォルダ C:\Users\(ユーザ名)\Downloads\struts-7.0.0-all\struts-7.0.0 |
|
解凍するファイル
C:\Users\(ユーザ名)\Downloads\struts-7.0.0-all\struts-7.0.0\apps\struts2-rest-showcase-7.0.0.war 解凍するとできるフォルダ C:\Users\(ユーザ名)\Downloads\struts-7.0.0-all\struts-7.0.0\apps\struts2-rest-showcase-7.0.0 |
|
コピー元
C:\Users\(ユーザ名)\Downloads\struts-7.0.0-all\struts-7.0.0\apps\struts2-rest-showcase-7.0.0\WEB-INF\lib\* コピー先 C:\pleiades\2024-12\workspace\(プロジェクト名)\src\main\webapp\WEB-INF\lib (重要)コピー先から以下のjarファイルを削除 struts2-rest-plugin-7.0.0.jar |
|
package test3.sample.model; public class MessageStore { private String message; public MessageStore() { setMessage("Hello Struts User"); } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public String toString() { return message + " (from toString)"; } } |
|
package test3.sample.model; public class Person { private String firstName; private String lastName; private String email; private int age; public String getFirstName() { return firstName; } public void setFirstName(String firstName) { this.firstName = firstName; } public String getLastName() { return lastName; } public void setLastName(String lastName) { this.lastName = lastName; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public int getAge() { return age; } public void setAge( int age) { this.age = age; } public String toString() { return "First Name: " + getFirstName() + " Last Name: " + getLastName() + " Email: " + getEmail() + " Age: " + getAge() ; } } |
|
package test3.sample.action; import org.apache.struts2.ActionSupport; import org.apache.struts2.interceptor.parameter.StrutsParameter; import test3.sample.model.MessageStore; public class HelloWorldAction extends ActionSupport { private static final long serialVersionUID = 1L; private MessageStore messageStore; private static int helloCount = 0; public int getHelloCount() { return helloCount; } public void setHelloCount(int helloCount) { HelloWorldAction.helloCount = helloCount; } private String userName; @StrutsParameter(depth = 1) public String getUserName() { return userName; } @StrutsParameter(depth = 1) public void setUserName(String userName) { this.userName = userName; } public String execute() throws Exception { messageStore = new MessageStore() ; //Action included a query string parameter of userName //or a form field with name of userName if (userName != null) { messageStore.setMessage( messageStore.getMessage() + " " + userName); } helloCount++; return SUCCESS; } @StrutsParameter(depth = 1) public MessageStore getMessageStore() { return messageStore; } @StrutsParameter(depth = 1) public void setMessageStore(MessageStore messageStore) { this.messageStore = messageStore; } } |
|
package test3.sample.action; import test3.sample.model.Person; import org.apache.struts2.ActionSupport; import org.apache.struts2.interceptor.parameter.StrutsParameter; public class Register extends ActionSupport { private static final long serialVersionUID = 1L; private Person personBean; public String execute() throws Exception { return SUCCESS; } public void validate(){ if ( personBean.getFirstName().length() == 0 ){ //addFieldError( "personBean.firstName", "First name is required." ); addFieldError( "personBean.firstName", getText("personBean.firstName_missing") ); } if ( personBean.getEmail().length() == 0 ){ //addFieldError( "personBean.email", "Email is required." ); addFieldError( "personBean.email", getText("personBean.email_missing" ) ); } if ( personBean.getAge() < 18 ) { //addFieldError( "personBean.age", "Age is required and must be 18 or older" ); addFieldError( "personBean.age", getText("personBean.age_missing") ); } } @StrutsParameter(depth = 1) public Person getPersonBean() { return personBean; } @StrutsParameter(depth = 1) public void setPersonBean(Person person) { personBean = person; } } |
|
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE html> <html charset="UTF-8"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Basic Struts 2 Application - Welcome</title> </head> <body> <h1>Welcome to Struts 2</h1> <p><a href="<s:url namespace='' action='hello'/>">Hello World</a></p> <s:url namespace='' action="hello" var="helloLink"> <s:param name="userName">Bruce Phillips</s:param> </s:url> <p><a href="${helloLink}">Hello Bruce Phillips</a></p> <p>Get your own personal hello by filling out and submitting this form.</p> <s:form namespace='' action="hello"> <s:textfield name="userName" label="Your name" /> <s:submit value="Submit" /> </s:form> <s:url namespace='' action="registerInput" var="registerInputLink" > <s:param name="request_locale">en</s:param> </s:url> <p><a namespace='' href="${registerInputLink}">Please register</a> for our prize drawing.</p> <h3>登録 日本語</h3> <s:url namespace='' action="registerInput" var="registerInputLinkJA"> <s:param name="request_locale">ja</s:param> </s:url> <p>賞を授与するため<a href="${registerInputLinkJA}">登録してください</a></p> <%-- --%> <hr /> <s:text name="contact" /> <%-- <br> <s:i18n name="global"> <s:text name="contact" /> </s:i18n> <br> <s:i18n name="global_en"> <s:text name="contact" /> </s:i18n> --%> </body> </html> |
|
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE html> <html charset="UTF-8"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Hello World!</title> </head> <body> <h1><s:text name="greeting" /></h1> <h2><s:property value="messageStore.message" /></h2> <p>I've said hello <s:property value="helloCount" /> times!</p> <p><s:property value="messageStore" /></p> <p><a href="<s:url action='index' />" >Return to home page</a>.</p> <hr /> <s:text name="contact" /> </body> </html> |
|
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE html> <html charset="UTF-8"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Register</title> <s:head /> </head> <body> <h1><s:text name="greeting" /></h1> <h3><s:text name="instructions" /></h3> <s:form action="registerExec"> <s:textfield key="personBean.firstName" /> <s:textfield key="personBean.lastName" /> <s:textfield key="personBean.email" /> <s:textfield key="personBean.age" /> <s:submit key="submit" /> </s:form> <hr /> <s:text name="contact" /> </body> </html> |
|
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE html> <html charset="UTF-8"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Registration Successful</title> </head> <body> <h3><s:text name="thankyou" /></h3> <p>Your registration information: <s:property value="personBean" /> </p> <p><a href="<s:url action='index' />" >Return to home page</a>.</p> <hr /> <s:text name="contact" /> </body> </html> |
|
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.5//EN" "https://struts.apache.org/dtds/struts-2.5.dtd"> <struts> <constant name="struts.devMode" value="true" /> <constant name="struts.custom.i18n.resources" value="global" /> <constant name="struts.allowlist.packageNames" value="test3.sample" /> <package name="basicstruts2" extends="struts-default"> <!-- If no class attribute is specified the framework will assume success and render the result index.jsp --> <!-- If no name value for the result node is specified the success value is the default --> <action name="index"> <result>/index.jsp</result> </action> <!-- If the URL is hello.action then call the execute method of class HelloWorldAction. If the result returned by the execute method is success render the HelloWorld.jsp --> <action name="hello" class="test3.sample.action.HelloWorldAction" method="execute"> <result name="success">/HelloWorld.jsp</result> </action> <action name="registerInput" class="test3.sample.action.Register" method="input" > <result name="input">/register.jsp</result> </action> <action name="registerExec" class="test3.sample.action.Register" method="execute"> <result name="success">/thankyou.jsp</result> <result name="input">/register.jsp</result> </action> </package> </struts> |
|
<?xml version="1.0" encoding="UTF-8"?> <!-- /* * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ --> <Configuration> <Appenders> <Console name="STDOUT" target="SYSTEM_OUT"> <PatternLayout pattern="%d %-5p [%t] %C{2} (%F:%L) - %m%n"/> </Console> </Appenders> <Loggers> <Logger name="org.apache.struts2" level="info"/> <Logger name="test3" level="debug"/> <Root level="warn"> <AppenderRef ref="STDOUT"/> </Root> </Loggers> </Configuration> |
|
<?xml version="1.0" encoding="UTF-8"?> <web-app> <display-name>test3</display-name> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.jsp</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>index</welcome-file> </welcome-file-list> </web-app> |
| contact=For assistance contact <a href='mailto:contact@email.com'>contact@email.com</a> |
| contact=For assistance contact <a href='mailto:contact@email.com'>contact@email.com</a> |
| contact=アシストを希望するにはコンタクトして下さい<a href='mailto:contact@email.com'>contact@email.com</a> |
|
greeting=Welcome to The Wonderful World of Struts 2 instructions=Register for a prize by completing this form. |
|
greeting=Welcome to The Wonderful World of Struts 2 instructions=Register for a prize by completing this form. |
|
greeting=ようこそStrutsの素晴らしい世界へ instructions=賞を授与するためこのフォームを登録 |
|
personBean.firstName=First name personBean.firstName_missing=First name is required. personBean.lastName=Last name personBean.age=Age personBean.age_missing=Age is required and must be 18 or older personBean.email=Email personBean.email_missing=Email is required. thankyou=Thank you for registering %{personBean.firstName}. submit=Register |
|
personBean.firstName=First name personBean.firstName_missing=First name is required. personBean.lastName=Last name personBean.age=Age personBean.age_missing=Age is required and must be 18 or older personBean.email=Email personBean.email_missing=Email is required. thankyou=Thank you for registering %{personBean.firstName}. submit=Register |
|
personBean.firstName=名 personBean.firstName_missing=名は必須入力です personBean.lastName=姓 personBean.age=年齢 personBean.age_missing=年齢は必須入力です。18歳以上である必要があります personBean.email=Eメール personBean.email_missing=Eメールは必須入力です thankyou=登録ありがとうございます。 %{personBean.firstName}さん submit=登録 |