|
解凍するファイル
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 |
|
Enter Password: (管理者 root のパスワード) |
|
grant all on sakila.* to testuser; |
|
コピー元
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 |
|
コピー元
C:\Users\(ユーザ名)\Downloads\mysql-connector-j-9.2.0\mysql-connector-j-9.2.0 コピー先 C:\pleiades\2024-12\workspace\(プロジェクト名)\src\main\webapp\WEB-INF\lib |
|
コピー元
C:\Users\(ユーザ名)\Downloads\commons-dbcp2-2.13.0-bin\commons-dbcp2-2.13.0 コピー先 C:\pleiades\2024-12\workspace\(プロジェクト名)\src\main\webapp\WEB-INF\lib |
|
package test6.sample.model; public class Actor { private String actorId; private String firstName; private String lastName; private String lastUpdate; public String getActorId() { return actorId; } public void setActorId(String actorId) { this.actorId = actorId; } 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 getLastUpdate() { return lastUpdate; } public void setLastUpdate(String lastUpdate) { this.lastUpdate = lastUpdate; } } |
|
package test6.sample.dao; import javax.naming.Context; import javax.naming.InitialContext; import javax.sql.DataSource; public class InitDataSource { private static Context context = null; private static DataSource ds = null; public static DataSource getInstance() throws Exception { if (context == null) { context = new InitialContext(); } if (ds == null) { ds = (DataSource)context.lookup("java:comp/env/sakila"); } return ds; } } |
|
package test6.sample.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.List; import javax.sql.DataSource; import test6.sample.model.Actor; public class ActorDAO { DataSource ds; public ActorDAO() throws Exception { ds = InitDataSource.getInstance(); } public List<Object> selectActor() throws Exception { PreparedStatement ps = null; ResultSet rs = null; List<Object> actorList = new ArrayList<>(); Connection conn = ds.getConnection(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String SQL = "SELECT ACTOR_ID,FIRST_NAME,LAST_NAME,LAST_UPDATE FROM ACTOR"; try { ps = conn.prepareStatement(SQL); rs = ps.executeQuery(); while(rs.next()){ Integer actor_id = rs.getInt("actor_id"); String first_name = rs.getString("first_name"); String last_name = rs.getString("last_name"); String last_update = sdf.format(rs.getTimestamp("last_update")); Actor actor = new Actor(); actor.setActorId((String)actor_id.toString()); actor.setFirstName(first_name); actor.setLastName(last_name); actor.setLastUpdate(last_update); actorList.add(actor); } } finally { ps.close(); rs.close(); conn.close(); } return actorList; } } |
|
package test6.sample.action; import java.util.ArrayList; import java.util.List; import org.apache.struts2.ActionSupport; import test6.sample.dao.ActorDAO; public class ActorListAction extends ActionSupport { private static final long serialVersionUID = 1L; private List<Object> actorList = new ArrayList<>(); public String execute() throws Exception { ActorDAO dao = new ActorDAO(); actorList = dao.selectActor(); return SUCCESS; } public List<Object> getActorList() { return actorList; } public void setActorList(List<Object> actorList) { this.actorList = actorList; } } |
|
<%@ 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>Actor List</title> </head> <body> <table> <tr> <td>actorId</td> <td>firstName</td> <td>lastName</td> <td>lastUpdate</td> </tr> <s:iterator value="actorList"> <tr> <td><s:property value="actorId"/></td> <td><s:property value="firstName"/></td> <td><s:property value="lastName"/></td> <td><s:property value="lastUpdate"/></td> </tr> </s:iterator> </table> </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.enable.DynamicMethodInvocation" value="false"/> <constant name="struts.devMode" value="true"/> <constant name="struts.allowlist.packageNames" value="test6.sample" /> <package name="test6" extends="struts-default"> <action name="dbtest" class="test6.sample.action.ActorListAction" method="execute"> <result name="success">/actorList.jsp</result> </action> </package> <!-- Add addition packages and configuration here. --> </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="test6" level="debug"/> <Root level="warn"> <AppenderRef ref="STDOUT"/> </Root> </Loggers> </Configuration> |
|
<?xml version="1.0" encoding="UTF-8"?> <web-app> <display-name>test6</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> |
|
<?xml version="1.0" encoding="UTF-8"?> <Context reloadable="true"> <Resource name="sakila" auth="Container" type="javax.sql.DataSource" driverClassName="com.mysql.cj.jdbc.Driver" url="jdbc:mysql://localhost:3306/sakila" connectionProperties="allowPublicKeyRetrieval=true;autoReconnect=true;verifyServerCertificate=false;useSSL=false;requireSSL=false;useUnicode=true;characterEncoding=UTF-8;" username="testuser" password="userpass" validationQuery="select 1"/> </Context> |
|
<!DOCTYPE html> <html> <head> <META HTTP-EQUIV="Refresh" CONTENT="0;URL=dbtest"> </head> <body> <p>Loading ...</p> </body> </html> |
|
use sys;
select conn_id, user, db, state from session; |