// list.add(new DbTransactionInitializer());
MockupFacade 
public final boolean mockupFlg = true;



TestformFormBeanーTestformFormBean
        this.M1.newRow();


info.M1.setDisplayRowCount(10);

sqlserver 2014 express をインストール時にssmsが一覧に表示されないと嘆いている方

別ダウンロードだったのね。。。よくみてなかった。。。

f:id:oguri0220:20161120005342p:plain

'*******************************************************************************
'   フォルダを指定すると、フォルダ内のエクセルファイルを開いて、
'  任意のシートをコピーして集約用ファイルにコピーするマクロ
'   (集約用ファイルはダイアログで指定したフォルダの1階層上に作成されます)
'*******************************************************************************
Option Explicit

''
'取得したい内容に応じて随時変更して欲しい項目たち
''
    'SHEETNAME_NG_WORD-データを取得したく無いシート名に含まれる名前を逐次追加
    
    'それぞれのシートのコピーを集約用ファイル名
    Public Const PASTEFILENAME = "AllReports"

''
'変更不要
''
    'データを取得したく無いシート名に含まれる名前を指定
    Public SHEETNAME_NG_WORD As Variant
    
    '現在のシート数
    Public NOWSHEETCOUNT As Integer

    Public Enum CellBound
        RightBound = 0
        Leftbound = 1
        UpBound = 2
        DownBound = 3
    End Enum

    Public Type SearchRequirement
        Bound As CellBound
        OffsetValue As Integer
        CellName As String
    End Type

    Public Type SearchCellType
        TargetCellName As String
        TargetSheetName As String
        EndOfData As String
        Requirements() As SearchRequirement
    End Type



'*******************************************************************************
'   フォルダ選択ダイアログにて、コピーしたいEXCELファイルが入っているフォルダを
'  取得する
'*******************************************************************************
Function FolderSelect()
    Dim dlg As FileDialog
    Dim fold_path As String
    
    Set dlg = Application.FileDialog(msoFileDialogFolderPicker)
    
    'キャンセルボタンクリック時にマクロを終了
    If dlg.Show = False Then Exit Function
    
    'フォルダーのフルパスを変数に格納
    fold_path = dlg.SelectedItems(1)
    
    '関数名に対して値を設定すると、戻り値を設定したことになる
    FolderSelect = fold_path
End Function


'*******************************************************************************
'   Main
'*******************************************************************************
Sub CopyExcelSheet()
    Dim CPath As String
    Dim F As Object
    Dim i As Integer
    Dim dWB As Workbook
    Dim strNewFileName As String
    
    SHEETNAME_NG_WORD = Array("参考", "old_")
    
    NOWSHEETCOUNT = 0
       
    '集約用ブックを作成
    Set dWB = Workbooks.Add
    
    CPath = FolderSelect()
    
    If CPath = "" Then Exit Sub
    
    'フォルダが同じだと2回目以降に前に作ったシートの中もコピーしてくるため、
    '一つ上の階層のフォルダに作成
    strNewFileName = ".\" & PASTEFILENAME
    
    Application.ScreenUpdating = False
       
    'フォルダ内のファイルを一つずつ取得
    For Each F In CreateObject("Scripting.FileSystemObject").GetFolder(CPath).Files
        If Right(F.Name, 4) = ".xls" Or Right(F.Name, 5) = ".xlsx" Then
            
            'EXCELファイルの場合は情報取得処理
            'Call CopyExcelSheets(dWB, CPath, F.Name)
            Call GetExcelData(dWB, CPath, F.Name)
        End If
    Next
        
    'Excelバージョンによって、ファイルの保存方法を変更
    Application.DisplayAlerts = False
    If Val(Application.Version) < 12 Then
        dWB.SaveAs Filename:=strNewFileName
    Else
        dWB.SaveAs Filename:=strNewFileName, FileFormat:=XlFileFormat.xlExcel8
    End If
    dWB.Close
    
    Application.ScreenUpdating = True
    
    MsgBox "終了"
End Sub


'*******************************************************************************
'   エクセルシートコピー用関数
'*******************************************************************************
Function CopyExcelSheets(dWB As Workbook, xPath As String, xName As String)
    Dim xlsWkb As Object
    Dim isExcelCopy As Boolean
    Dim i As Integer
    Dim Sht As Worksheet

    
    'ファイルを開く
    Set xlsWkb = Workbooks.Open(xPath & "\" & xName)
    
    'ファイルからシートを抽出
    For Each Sht In xlsWkb.Worksheets
    
        isExcelCopy = True
        
        For i = 0 To UBound(SHEETNAME_NG_WORD) - LBound(SHEETNAME_NG_WORD)
            If InStr(Sht.Name, SHEETNAME_NG_WORD(i)) > 0 Then
                'シート名にNGワードが合ったらコピーしない
                isExcelCopy = False
            End If
        Next
        
        If isExcelCopy = True Then
            NOWSHEETCOUNT = NOWSHEETCOUNT + 1
            
            'シートをコピー
            Sht.Copy After:=dWB.Worksheets(dWB.Worksheets.Count)
            
            'ActiveSheet.Cells(1).PasteSpecial Paste:=xlValues
            
            'シート名を重複しない...ハズの値に変更
            ActiveSheet.Name = NOWSHEETCOUNT & Sht.Name
            
            Application.CutCopyMode = False
        End If
        
        
    Next Sht
    
    xlsWkb.Close:
    Set xlsWkb = Nothing
End Function

'*******************************************************************************
'   データ取得用関数
'*******************************************************************************
Function GetExcelData(dWB As Workbook, xPath As String, xName As String)
    Dim xlsWkb As Object
    Dim isExcelCopy As Boolean
    Dim i As Integer
    Dim Sht As Worksheet
    
    Dim jyoken As SearchCellType
    Dim Target As Range
    
    jyoken.TargetCellName = "機能"
    jyoken.TargetSheetName = ""
    jyoken.EndOfData = ""
    ReDim jyoken.Requirements(1)
    
    jyoken.Requirements(0).CellName = "aa"
    jyoken.Requirements(0).Bound = RightBound
    jyoken.Requirements(0).OffsetValue = 4
    
    
    'ファイルを開く
    Set xlsWkb = Workbooks.Open(xPath & "\" & xName)
    Dim FoundCell As Range, FirstCell As Range
    'ファイルからシートを抽出
    For Each Sht In xlsWkb.Worksheets
    
        isExcelCopy = True
        
        If jyoken.TargetSheetName <> "" And Sht.Name <> jyoken.TargetSheetName Then
        
        Else
            Target = SearchMatchCell(Sht, jyoken)
        End If
        
        'For i = 0 To UBound(SHEETNAME_NG_WORD) - LBound(SHEETNAME_NG_WORD)
        '    If InStr(Sht.Name, SHEETNAME_NG_WORD(i)) > 0 Then
        '        'シート名にNGワードが合ったらコピーしない
        '        isExcelCopy = False
       '     End If
        'Next
        
        If Not Target Is Nothing Then
            Do
                Set FoundCell = Cells.FindNext(Target)
        
                If FoundCell.Address = Target.Address Then
                    Exit Function
                Else
                    Target.Copy Destination:=dWB.Worksheets("Sheet2").Range("A1")
                End If
            Loop
        End If
        
        'If isExcelCopy = True Then
        '    NOWSHEETCOUNT = NOWSHEETCOUNT + 1
            
            
        '    dWB.Worksheets("Sheet2").Value = ""
            
            'シートをコピー
            'Sht.Copy After:=dWB.Worksheets(dWB.Worksheets.Count)
            
            'ActiveSheet.Cells(1).PasteSpecial Paste:=xlValues
            
            'シート名を重複しない...ハズの値に変更
            'ActiveSheet.Name = NOWSHEETCOUNT & Sht.Name
            
            'Application.CutCopyMode = False
        'End If
        
        
    Next Sht
    
    xlsWkb.Close:
    Set xlsWkb = Nothing
End Function


Function SearchMatchCell(sheet As Worksheet, searchName As SearchCellType) As Range
    Dim Rng As Range
    Dim FoundCell As Range, FirstCell As Range, Target As Range
    
    Set FoundCell = sheet.Cells.Find(What:=searchName.TargetCellName, LookIn:=xlValues, LookAt:=xlWhole)
    If FoundCell Is Nothing Then
        '条件に見合うセルがない
        Exit Function
    ElseIf Not FoundCell Is Nothing And Sgn(searchName.Requirements) = 0 Then
        '追加条件なし
        SearchMatchCell = FoundCell
        Exit Function
    Else
        '追加条件あり
        Set FirstCell = FoundCell
        Set Target = FoundCell
    End If
    
    Do
        Dim j As Long
        Dim isMatchCell As Boolean
        
        For j = LBound(searchName.Requirements) To UBound(searchName.Requirements)
        
            isMatchCell = True
'If FoundCell.MergeCells Then
            '    If searchName.Requirements(j).Bound = CellBound.RightBound Then
            '        offset = FoundCell.MergeArea.Columns.Count
            '    ElseIf searchName.Requirements(j).Bound = CellBound.DownBound Then
            '        offset = FoundCell.MergeArea.Rows.Count
            '    End If
            'End If
            
            
            Select Case searchName.Requirements(j).Bound
                Case CellBound.RightBound
                    If sheet.Cells(FoundCell.Row, FoundCell.Column + searchName.Requirements(j).OffsetValue).Value <> _
                        searchName.Requirements(j).CellName Then
                            isMatchCell = False
                            Exit For
                    End If
                Case CellBound.Leftbound
                    If sheet.Cells(FoundCell.Row, FoundCell.Column - searchName.Requirements(j).OffsetValue).Value <> _
                        searchName.Requirements(j).CellName Then
                            isMatchCell = False
                            Exit For
                    End If
                Case CellBound.UpBound
                    If sheet.Cells(FoundCell.Row - searchName.Requirements(j).OffsetValue, FoundCell.Column).Value <> _
                        searchName.Requirements(j).CellName Then
                            isMatchCell = False
                            Exit For
                    End If
                Case CellBound.DownBound
                    If sheet.Cells(FoundCell.Row + searchName.Requirements(j).OffsetValue, FoundCell.Column + searchName.Requirements(j).OffsetValue).Value <> _
                        searchName.Requirements(j).CellName Then
                            isMatchCell = False
                            Exit For
                    End If
            End Select
'Msg = Msg & searchName(j).TargetCellName & vbCrLf
        Next j
        
        If isMatchCell Then
            '合致したセルとして返却
            SearchMatchCell = FoundCell
            Exit Function
        Else
            Set FoundCell = sheet.Cells.FindNext(FoundCell)
    
            If FoundCell.Address = FirstCell.Address Then
                Exit Function
            End If
        End If
    Loop
End Function

            org.w3c.dom.Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
            Element rootElement = document.createElement("items");
            document.appendChild(rootElement);
            Element element = document.createElement("item");
            rootElement.appendChild(element);
            Text textContents = document.createTextNode("VALUE");
            element.appendChild(textContents);
            Attr attribute = document.createAttribute("id");
            attribute.setValue("ID");
            element.setAttributeNode(attribute);

・ファイアーウォール停止
systemctl disable firewalld.service

・tomcatインストール
    wget http://ftp.jaist.ac.jp/pub/apache/tomcat/tomcat-8/v8.5.6/bin/apache-tomcat-8.5.6.tar.gz

    useradd -s /sbin/nologin tomcat

    tar -xzvf ~/apache-tomcat-8.5.6.tar.gz

    mkdir /opt/apache-tomcat
    mv ~/apache-tomcat-8.5.6 /opt/apache-tomcat
    chown -R tomcat:tomcat /opt/apache-tomcatjavaインストール
    rpm -ihv /home/rootuser/ダウンロード/jdk-8u101-linux-x64.rpm 
    /usr/sbin/update-alternatives --install /usr/bin/java java /usr/java/jdk1.8.0_101/bin/java 1000
    /usr/sbin/update-alternatives --set java /usr/java/jdk1.8.0_101/bin/java

vim  /etc/profile
JRE_HOME=/usr/java/default
CATALINA_HOME=/opt/apache-tomcat/apache-tomcat-8.5.6/
export JRE_HOME CATALINA_HOME

sudo -u tomcat /opt/apache-tomcat/apache-tomcat-8.5.6/bin/startup.sh
sudo -u tomcat /opt/apache-tomcat/apache-tomcat-8.5.6/bin/shutdown.sh

・ホストOSからゲストOS接続
    Virtualbox ファイルー環境設定
    ホストオンリーネットワーク追加
    192.168.56.1
    255.255.255.0

    192.168.56.100
    255.255.255.0
    192.168.56.101
    192.168.56.254

    Virtualbox 仮想マシンー設定
    ホストオンリーネットワーク追加

    起動しない場合、
    コントロール パネル\ネットワークとインターネット\ネットワーク接続
    のVirtualBox Host-Only Networkを有効か


    ・vim /etc/sysconfig/network-scripts/ifcfg-eth1
    CE=eth1
    TYPE=Ethernet
    ONBOOT=yes
    BOOTPROTO=static
    HWADDR=08:00:27:3A:EA:37
    NAME="System eth1"
    IPADDR=192.168.56.100
    NETMASK=255.255.255.0
    NETWORK=192.168.56.0


・war実行
    find / -name "catalina*"
    vim /etc/profile
    CATALINA_HOME=/opt/apache-tomcat/apache-tomcat-8.5.6/
    →    warプロジェクトコピー




・リモートデバッグ
    vim /opt/apache-tomcat/apache-tomcat-8.5.6/bin/catalina.sh
    →     JPDA_ADDRESS="192.168.56.100:8000"



    vim /opt/apache-tomcat/apache-tomcat-8.5.6/bin/startup.s
    →        exec "$PRGDIR"/"$EXECUTABLE" jpda start "$@"


    デバッグデバッグの構成をクリック
    開いたダイアログから「リモートJavaアプリケーション」を探しダブルクリックするとプロジェクト名のデバッグ構成が作成されます

・
        Connection conn =
        DriverManager.getConnection
        ("jdbc:oracle:thin:system/admin@localhost:1521:XE");
        
        Statement stmt = conn.createStatement();
        String sql = "insert into TABLE1 values ('001', 'てすと')";
        int num = stmt.executeUpdate(sql);

プロジェクトを右クリックー実行ー実行の構成
クラスパスタブ
外部jarの追加
C:\oraclexe\app\oracle\product\11.2.0\server\jdbc\lib

    
セッションの再作成方法
            ((SessionMap<String, Object>)ActionContext.getContext().getSession()).invalidate();
            HttpSession newsession = ServletActionContext.getRequest().getSession(true);
            
            ServletActionContext.getRequest().getSession(true).invalidate();
      だとstruts2でセッションが消えてることに気づけない?

・web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
    <display-name>Struts2InterceptorExample</display-name>

    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
    </filter>

<!--     <listener> -->
<!--         <listener-class>com.listeners.SessionListener</listener-class> -->
<!--     </listener> -->

    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    
    <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    
    <session-config>
        <session-timeout>1</session-timeout>
    </session-config>
</web-app>




・welcome.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome Page</title>
</head>
<body>
    <h3><s:actionerror/>
        Welcome<br/>
        <s:set var="data" value="#session.userInfo.userId" scope="request"/>
        <s:textfield label="ユーザーID" type="text" value="%{#request.data}" />
        <br/>
        <s:property value="#session.userInfo.password"/>
    </h3>
    <s:form method="post" action="logout">
        <s:submit value="ログアウト" />
    </s:form>
</body>
</html>


・login.jsp
<!DOCTYPE HTML>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Insert title here</title>
</head>
<body>
    <s:actionerror/>
    <s:form method="post" action="auth">
        <s:textfield label="ユーザーID" type="text" name="userInfo.userId" />
        <br/>
        <s:password label="パスワード" type="password" name="userInfo.password" />
        <s:submit value="ログイン" />
    </s:form>
</body>
</html>


・struts.xml
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
    "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
    <constant name="struts.convention.result.path" value="/"></constant>
    
    <!-- 任意のメソッドの実行を許可しない -->
    <constant name="struts.enable.DynamicMethodInvocation" value="false" />
    
    <package name="user" namespace="/" extends="struts-default">
        <interceptors>
            <interceptor name="session"
                class="com.interceptors.SessionInterceptor"></interceptor>
            <interceptor-stack name="sessionStack">
                <interceptor-ref name="session"></interceptor-ref>
                <interceptor-ref name="defaultStack"></interceptor-ref>
            </interceptor-stack>
        </interceptors>

        <default-interceptor-ref name="sessionStack"></default-interceptor-ref>

        <global-results>
            <result name="login" type="redirect">/login.action</result>
<!--             <result name="login">/login.action</result> -->
        </global-results>

<!--         <action name="sessionAuth"> -->
<!--             <interceptor-ref name="sessionStack" /> -->
<!--             <result name="success">/success.jsp</result> -->
<!--             <result name="session">/sessionexpired.jsp</result> -->
<!--         </action> -->

        <action name="login">
            <interceptor-ref name="defaultStack"></interceptor-ref>
            <result>/WEB-INF/pages/login.jsp</result>
        </action>
        
        <action name="logout" class="com.actions.LogoutAction">
            <interceptor-ref name="defaultStack"></interceptor-ref>
        </action>

        <action name="auth" class="com.actions.LoginAction">
            <interceptor-ref name="defaultStack"></interceptor-ref>
            <result name="success" type="redirect">/welcome.action</result>
            <result name="input">/WEB-INF/pages/login.jsp</result>
        </action>

<!--         <action name="welcome" class="com.actions.WelcomeAction"> -->
        <action name="welcome">
            <result name="success">/WEB-INF/pages/welcome.jsp</result>
        </action>
    </package>

</struts>


・SessionListener.java
package com.listeners;

import javax.servlet.http.HttpSessionBindingEvent;
import javax.servlet.http.HttpSessionBindingListener;

public class SessionListener implements HttpSessionBindingListener{
    private String aaa;
    
    @Override
    public void valueBound(HttpSessionBindingEvent arg0) {
        // TODO 自動生成されたメソッド・スタブ
        System.out.println("valueBound");
    }

    @Override
    public void valueUnbound(HttpSessionBindingEvent arg0) {
        // TODO 自動生成されたメソッド・スタブ
        System.out.println("valueUnBound");
    }

}


・SessionInterceptor.java
package com.interceptors;

import java.util.Map;

import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;

@Results({
    @Result(name = Action.SUCCESS, location="/WEB-INF/pages/welcome.jsp"),
})
public class SessionInterceptor extends AbstractInterceptor {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    @Override
    public String intercept(ActionInvocation invocation) throws Exception {
        Map<String,Object> session = invocation.getInvocationContext().getSession();
    
        if(session.isEmpty()) {
            return Action.LOGIN;
        } else {
            return invocation.invoke();
        }
    }
}



・UserInfo.java
package com.beans;

public class UserInfo {
    
    private String userId;
    private String password;
    
    public UserInfo(){}
    public UserInfo(String userId, String password) {
        this.userId = userId;
        this.password = password;
    }
    public String getUserId() {
        return userId;
    }
    public void setUserId(String userName) {
        this.userId = userName;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    
    

}


・LogoutAction.java
package com.actions;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;

public class LogoutAction extends ActionSupport {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    
    public String execute() {
        HttpSession session = ServletActionContext.getRequest().getSession(true);
        session.invalidate();
        
        return Action.LOGIN;
    }
}



・LoginAction.java
package com.actions;

import javax.servlet.http.HttpSession;
import java.sql.*;

import org.apache.struts2.ServletActionContext;
import com.beans.UserInfo;
import com.opensymphony.xwork2.ActionSupport;


/**
 * ログイン処理を行うアクションメソッドです。
 *
 */
public class LoginAction extends ActionSupport {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    
    private UserInfo userInfo;
    
    /**
     * @return userInfo
     */
    public UserInfo getUserInfo() {
        return userInfo;
    }

    /**
     * @param userInfo セットする userInfo
     */
    public void setUserInfo(UserInfo userInfo) {
        this.userInfo = userInfo;
    }

//    public String execute() {
//        // ここに処理を記載するとvalidateの後で実行されてしまう。
//        return Action.SUCCESS;
//    }
    
    public void validate() {
        if ("admin".equals(userInfo.getUserId())) {
            ServletActionContext.getRequest().getSession(true).invalidate();
            HttpSession newsession = ServletActionContext.getRequest().getSession(true);
            newsession.setAttribute("userInfo", new UserInfo(userInfo.getUserId(), userInfo.getPassword()));
        } else {
            addActionError("userid または password が違います。");
        }
    }
}