게시물의 총 수

ResultSet 사용시

rs.last();

int totalRecode = rs.getRow();

 

레코드 사이즈

recordSize = 10;

한페이지당 보여줄 게시물의 갯수

 

Vector 사용시

int totalRecode = vector.size();

 

현제 보고 있는 페이지

currentPage = 1;

if(request.getParameter("currentPage") != null)

{

     currentPage = request.getParameter("currentPage");

}

 

현재 보고 있는 페이지 번호.

 

게시물에 따른 총 페이지 수

int totalPage = (int)Math.ceil((float)totalRecode/(float)recordSize);

 

게시물 번호

int num = totalRecode - ((currentPage-1) * recordSize);

 

블럭 사이즈

blockSize = 5;

 

네비게이션에 보여질 페이지 갯수

ex ) ◁ [ 1 ] [ 2 ] [ 3 ] [ 4 ] [ 5 ] ▷

 

네비게이션

시작 페이지 : int firstPage = currentPage - ((currentPage-1)%blockSize);
마지막 페이지 : int lastPage = firstPage + (blockSize-1);

 

네비게이션에 나오는 첫번째 페이지와 마지막 페이지

1, 2, 3, 4, 5 일때 1과 5

6, 7, 8, 9, 10 일때 6과 10

 

커서 포지션

int curPos = recordSize*(currentPage-1);

: 네비게이션의 각 페이지 별로 rs 객체 또는 백터의 커서 처음 시작 위치




Unix 환경이 Linux에서 Mysql을 설치하면

Window 환경과 다르게 쿼리문 자체에서 대소문자 구별을 해버린다.

그래서


아래와 같이 코드를 작성 할 경우, 


SELECT

A.SEQ

, A.SUBJECT

, B.SEQ as IMG_SEQ

, B.CONTENTS_NAME

, B.CONTENTS_ORI_NAME

, B.CONTENTS_PATH

, B.CONTENTS_TYPE

, B.TEXT1

FROM

ADMINBOARD A ,

ADMINIMG B

WHERE

A.SEQ= #seqId#

AND A.SEQ = b.BOARD_SEQ

AND A.IMG_CATEGORY = #imgCategory#

ORDER BY

A.KEYVISUAL_ORDER


org.springframework.web.util.NestedServletException: Request processing failed;

에러를 낸다


그래서 이럴 경우에는

아래와 같이 해결 한다.



servlet-context.xml


<beans xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:context="http://www.springframework.org/schema/context"

xmlns:mvc="http://www.springframework.org/schema/mvc"

xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd

http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">



<context:annotation-config /> // 애노테이션 방식 사용

<mvc:annotation-driven /> // MVC 애노테이션 방식 사용


// 기본 애노테이션들을 빈으로 등록해준다 src/leadweb/* 모든 하위 디렉토리

<context:component-scan base-package="leadweb.*" />


// 파일 형식의 업로드 기능을 사용하고자 할 때 등록하는 bean

<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver"/>


// 뷰 리졸버 - 컨트롤러와 jsp의 맵핑

<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">

<property name="prefix" value="/WEB-INF/jsp/"/>

<property name="suffix" value=".jsp"/>

</bean>


<mvc:interceptors>

<mvc:interceptor>

   <mvc:mapping path="/admin/**" /> // uri 가 context root/admin/** 모든 URL이 들어왔을때

// 인터셉터 등록

<bean class="leadweb.admin.interceptor.LoginCheckInterceptor" />

</mvc:interceptor>

</mvc:interceptors>


Spring Context Root 변경

아주 간단한 방법으로는

webapps/neli 를 url 상으로 "/" context root로 보이고 싶다면


$ cd ../tomcat7/conf/

$ sudo vim server.xml


열어 보면 기본 Host 설정이 

<Host name="localhost" appBase="webapps" ... >

이렇게 잡혀 있을텐데 appBase 부분을


<Host name="localhost" appBase="webapps/neli" ...>

로 변경 해주면 된다

Spring 톰캣 War 배포

Linux 서버에 접속한다.


$ cd /usr/share/tomcat7/webapps/

${catarina_home} 톰캣 홈 디렉토리로 간다


톰캣 홈 디렉토리인 webapps에다 neli.war 이름으로 파일을 올린다.


$ sudo service tomcat7 stop

톰캣 서버를 재시작한다.


/webapps/neli 라는 폴더가 생기며 이곳에 스프링 프로젝트가 Deploy 된다.


$cd /usr/share/tomcat7/conf

톰캣의 환경설정 파일디렉토리로 이동하여


$ echo $JAVA_HOME

> /usr/java/default


지금 현 자바 JDK버전이 깔린 위치를 확인 후,


$ sudo vim usr/share/tomcat7/conf/tomcat7.conf

로 연뒤 Tomcat7.conf 안의 JAVA_HOME도 똑같이 /usr/java/default 로 잡아준다.

(서버의 자바 홈디렉토리와 톰캣의 자바 홈디렉토리가 일치 하여야 class 파일을 컴파일 할때 버전이 맞지않다고 에러를 내지 않는다)

Maven 환경 셋팅

$ cd /home/ec2-user/

이동 (홈디렉토리로 이동)


$ wget http://mirrors.gigenet.com/apache/maven/maven-3/3.1.1/binaries/apache-maven-3.1.1-bin.tar.gz

해당 디렉토리에 maven을 download 받는다.


$ sudo tar -zxvf apache-maven-3.1.1-bin.tar.gz -C /opt/

/opt/ 폴더 내에 maven 압축 파일을 푼다


ln -s /opt/apache-maven-3.0.3 /opt/maven

Symbolic Link를 걸어준다 (생략 가능)


$ sudo vi /etc/profile

환경변수를 등록하기 위해 /etc/profile을 편집기로 연다


 

M2_HOME=/opt/maven
PATH=$PATH:$M2_HOME/bin
export M2_HOME; export PATH;

변경된 /etc/profile을 수정한다


$ source /etc/profile 

변경된 시스템 적용


$ mvn -version 명령어를 입력하여 환경변수 설정이 되었는지 확인한다.


neli 접속 방법

putty 접속시

ip: ec2-54-199-221-176.ap-northeast-1.compute.amazonaws.com

pw: leadweb123456

ssh key: neli_ssh.ppk


securecrt 접속시 

ssh key: neli_ssh_securecrt_Identity



구동정보

tomcat7 

시작: sudo service tomcat7 start
종료: sudo service tomcat7 stop

웹: http://ec2-54-199-221-176.ap-northeast-1.compute.amazonaws.com:8080/manager/status

admin/leadweb123456

mysql

시작: sudo service mysqld start
종료: sudo service mysqld stop


neli

http://ec2-54-199-221-176.ap-northeast-1.compute.amazonaws.com:8080/neli/

/usr/share/tomcat7/webapps/neli


설치순서

AMI t1.micro로 기본 설치 
ssh -i neli_ssh.pem ec2-user@54.199.215.255 접속

한국시간으로 변경 ('AWS 한국시간 변경 참조')


Timezone ?

리눅스를 새로 설치하고 나면 (AWS EC2 AMI도 Linux와 동일) 시간대(Timezone)을 맞추지 않으면, 리눅스의 date가 미국 태평양 시간인 PST로 표시됩니다. 즉 캘리포니아 현지 시간으로 표시됩니다. 이럴경우 한국 표준시인 KST로 변경해주어야 합니다.


Timezone 변경

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[ec2-user@ip-172-31-7-180 ~]$ date
Fri Aug  8 06:41:49 UTC 2014
 
[ec2-user@ip-172-31-7-180 ~]$ sudo date
Fri Aug  8 06:42:01 UTC 2014
 
[ec2-user@ip-172-31-7-180 ~]$ sudo cat /etc/localtime
TZif2UTCTZif2UTC
UTC0
 
[ec2-user@ip-172-31-7-180 ~]$ sudo rm /etc/localtime
 
[ec2-user@ip-172-31-7-180 ~]$ sudo ln -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime
 
[ec2-user@ip-172-31-7-180 ~]$ date
Fri Aug  8 15:48:27 KST 2014
 
[ec2-user@ip-172-31-7-180 ~]$ sudo date
Fri Aug  8 15:48:40 KST 2014


oracle java 설치 ('AWS 설치 – TimeZone 및 Java 설치')
yum install tomcat7 tomcat7-webapps tomcat7-docs-webapp tomcat7-admin-webapps

sudo service tomcat7 start
sudo service tomcat7 stop
http://ec2-54-199-221-176.ap-northeast-1.compute.amazonaws.com:8080/

yum install mysql-server

sudo service mysqld start
sudo service mysqld stop

mysql_secure_installation

모두 Y

mysql 초기 셋팅
mysqlworkbanch 접속

ssh key 는 .pem 파일 선택

http://www.youtube.com/watch?v=pZFSSVVdqmw

iptables -t nat -I PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

https://console.aws.amazon.com/ec2/v2/home?region=ap-northeast-1#


AWS 접속

https://console.aws.amazon.com/ec2/v2/home?region=ap-northeast-1#

AWS 기본설치

http://www.kimjmin.net/2014/01/aws_1/

AWS 한국시간 변경

sudo vi /etc/profile

TZ=Asia/Seoul
export TZ
source /etc/profile
date


AWS 접속방법(상세)

기본: ssh -i neli_ssh.pem ec2-user@54.199.215.255

puttygen 으로 pem 파일을 로드하여 pub, ppk 파일을 만든다. 
자동으로 ppk 파일이 서버의 .ssh/authorized_keys 파일에 복사 된다.

securecrt에서 create public key를 클릭 pub 파일을 만든다. (DSA 선택)
해당 파일을 AWS에 복사후 
※ssh-keygen -i -f ./Identity.pub >> .ssh/authorized_keys
하기 명령을 공개키를 authorized_keys에 등록 해준다.

암호: leadweb123456

AWS tomcat, mysql 설치

http://coenraets.org/blog/2011/11/set-up-an-amazon-ec2-instance-with-tomcat-and-mysql-5-minutes-tutorial/

mysql 까지 설치가 완료되면,

sudo service mysqld start

위 service로 mysql 구동 하여준다

 그리고mysql의 root 계정 패스워드를 초기화 해주어야 한다

(처음엔 password가 지정되어 있지 않으므로

> mysql -u root

로 접속하면 된다)

접속한 뒤 아래와 같이 비밀번호를 셋팅 해준다


Method 2 - Update or change password

MySQL stores usernames and passwords in the user table inside the MySQL database. You can directly update a password using the following method to update or change passwords:

1) Login to the MySQL server, type the following command at the shell prompt:


$ mysql -u root -p


2) Use the mysql database (type commands at the mysql> prompt):


mysql> use mysql;


3) Change password for a user:


mysql> update user set password=PASSWORD("newpass") where User='ENTER-USER-NAME-HERE';


4) Reload privileges:


mysql> flush privileges;
mysql> quit



AWS 설치 – TimeZone 및 Java 설치

http://www.kimjmin.net/2014/01/aws_2/


mysql 초기 셋팅

[root@ip-172-31-17-71 bin]# mysql -u root -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.5.34 MySQL Community Server (GPL)

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database neli
-> ;
Query OK, 1 row affected (0.00 sec)

mysql> use neli;
Database changed
mysql> create table test (
-> id integer not null auto_increment,
-> name varchar(255) not null,
-> body text not null,
-> primary key(id)
-> );
Query OK, 0 rows affected (0.03 sec)

mysql> create user 'neli_user'@'localhost' identified by 'leadweb123456';
Query OK, 0 rows affected (0.00 sec)

mysql> grant all privileges on neli.* to 'neli_user'@'localhost';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> quit
Bye
[root@ip-172-31-17-71 bin]#


mysql 인코딩 설정

$ vi /etc/my.cnf


[mysql]

default-character-set = utf8


[mysqld]

character-set-client-handshake=FALSE

init_connect="SET collation_connection = utf8_general_ci"

init_connect="SET NAMES utf8"

default-character-set = utf8

character-set-server = utf8

collation-server = utf8_general_ci


datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

# Disabling symbolic-links is recommended to prevent assorted security risks

symbolic-links=0


[client]

default-character-set = utf8


[mysqldump]

default-character-set = utf8


[mysqld_safe]

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid



그리고 재시작 
$ service mysqld restart 
Stopping MySQL: [ OK ] 
Starting MySQL: [ OK ] 

이제 최종적으로 status를 통해 서버와 mysql의 인코딩이 통일 되었는지 확인해보자 .

mysql> status
--------------
mysql  Ver 14.14 Distrib 5.1.61, for redhat-linux-gnu (x86_64) using readline 5.1

Connection id:          8
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.1.61 Source distribution
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /var/lib/mysql/mysql.sock
Uptime:                 27 min 16 sec

Threads: 1  Questions: 52  Slow queries: 0  Opens: 23  Flush tables: 1  Open tables: 11  Queries per second avg: 0.31
--------------

mysql> show variables like 'c%' ;

SELECT `AUTO_INCREMENT`

FROM  INFORMATION_SCHEMA.TABLES

WHERE TABLE_NAME   = 'adminboard'




40분동안 찾음;

쿼리문 예제)


UPDATE TABLE

SET

name = CASE

WHEN id = 1 THEN "lion"

WHEN id = 2 THEN "cat"

END

WHERE

name IN (1, 2)



아이바티스 예제)

<update id="modifyOrdering" parameterClass="java.util.List">

<![CDATA[

UPDATE ADMINBOARD

SET

KEYVISUAL_ORDER = CASE

]]>

<iterate conjunction=" ">

WHEN seq=#[].seqId#  THEN #[].keyviOrder# 

</iterate>

<![CDATA[

END

WHERE

KEYVISUAL_ORDER IN (1, 2, 3, 4, 5, 6);

]]>

</update> 

+ Recent posts