|
解凍するファイル
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\* コピー先 C:\pleiades\2024-12\workspace\(プロジェクト名)\src\main\webapp |
|
コピー元
C:\Users\(ユーザ名)\Downloads\struts-7.0.0-all\struts-7.0.0\apps\struts2-rest-showcase-7.0.0\WEB-INF\src\ava\* コピー先 C:\pleiades\2024-12\workspace\(プロジェクト名)\src\main\java |
|
コピー元
C:\Users\(ユーザ名)\Downloads\struts-7.0.0-all\struts-7.0.0\apps\struts2-rest-showcase-7.0.0\WEB-INF\* コピー先 C:\pleiades\2024-12\workspace\(プロジェクト名)\src\main\webapp\WEB-INF |
|
: <constant name="struts.convention.package.locators" value="example"/> <constant name="struts.allowlist.packageNames" value="org.demo.rest.example" /> <!-- ← 追加する行 --> <!-- Uncomment the lines below to use Jackson XML bindings instead of the XStream library to handle XML serialisations --> : : |
|
: : @Override @StrutsParameter(depth = 1) //← 追加する行 public Object getModel() { return (list != null ? list : model); } : |
|
解凍するファイル
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 test2.model;
public class MessageStore { private String message; public MessageStore() { message = "Hello Struts User"; } public String getMessage() { return message; } public String toString() { return message + " (from toString)"; } public void setMessage(String string) { message = string; } } |
|
package test2.action; import org.apache.struts2.ActionSupport; import org.apache.struts2.interceptor.parameter.StrutsParameter; import test2.model.MessageStore; public class HelloWorldAction extends ActionSupport { private MessageStore messageStore; private static int helloCount = 0; private String userName; public String execute() throws Exception { messageStore = new MessageStore() ; if (userName != null) { messageStore.setMessage( messageStore.getMessage() + " " + userName + " execute"); } helloCount++; return SUCCESS; } @StrutsParameter(depth = 1) public MessageStore getMessageStore() { return messageStore; } @StrutsParameter(depth = 1) public int getHelloCount() { return helloCount; } @StrutsParameter(depth = 1) public String getUserName() { return userName; } @StrutsParameter(depth = 1) public void setUserName(String userName) { this.userName = userName; } } |
|
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Hello World!</title> </head> <body> <h2><s:property value="messageStore.message" /></h2> <p><s:property value="messageStore" /></p> <p>I've said hello <s:property value="helloCount" /> times!</p> <a href='<s:url namespace="" action="index.jsp" />'>Back</a> <%-- --%> </body> </html> |
|
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="s" uri="/struts-tags" %> <!DOCTYPE html> <html> <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> <%-- namespaceがないのでうまくいかない <p><a href="<s:url action='hello'/>">Hello World</a></p> --%> <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> GET<br> <s:form namespace='' action="hello" method="get"> <s:textfield name="userName" label="Your name" /> <s:submit value="Submit" /> </s:form> POST<br> <s:form namespace='' action="hello"> <s:textfield name="userName" label="Your name" /> <s:submit value="Submit" /> </s:form> <%-- --%> </body> </html> |
|
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 6.0//EN" "https://struts.apache.org/dtds/struts-6.0.dtd"> <struts> <constant name="struts.devMode" value="true" /> <constant name="struts.action.extension" value="," /> <constant name="struts.allowlist.packageNames" value="test2" /> <!-- <constant name="struts.enable.DynamicMethodInvocation" value="true" /> <constant name="struts.configuration.xml.reload" value="false" /> --> <package name="test2" extends="struts-default"> <action name="index"> <result>/index.jsp</result> </action> <action name="hello" class="test2.action.HelloWorldAction" method="execute"> <result name="success">/HelloWorld.jsp</result> <result name="input">/index.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="test2" level="debug"/> <Root level="warn"> <AppenderRef ref="STDOUT"/> </Root> </Loggers> </Configuration> |
|
<?xml version="1.0" encoding="UTF-8"?> <web-app> <display-name>test2</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> |