- 아파치 ( 수동으로 실행 시 root 계정으로 실행 )

/etc/rc.d/rc.local 파일에 다음 내용을 추가

/usr/local/apache/bin/apachectl start



- 톰캣

/etc/rc.d/init.d/tomcat 이란 파일로 아래 내용 작성

==================================================

#!/bin/sh

# Source function library.

. /etc/rc.d/init.d/functions

source /etc/profile

export tomcat_HOME=톰캣 경로

# See how we were called.

case "$1" in

start)

echo -n "Starting tomcat EXPERIMENTAL: "

daemon $tomcat_HOME/bin/startup.sh

echo

;;

stop)

echo -n "Shutting down tomcat EXPERIMENTAL: "

daemon $tomcat_HOME/bin/shutdown.sh

echo

;;

restart)

$0 stop

$0 start

;;

*)

echo "Usage: $0 {start|stop|restart}"

exit 1

esac

exit 0

==================================================


# chmod 755 /etc/rc.d/init.d/tomcat  권한 설정

# /etc/rc.d/init.d/tomcat   실행테스트


Usage : {start|stop|restart} 이 메세지가 뜨면 완성




출처: http://www.parkjinsu.com/23 [SomeThing]



==================

좀더 많은 내용


#!/bin/bash
#
# tomcat
#
# chkconfig: 345 96 30
# description:  Start up the Tomcat servlet engine.
#
# processname: java
# pidfile: /var/run/tomcat.pid
#
### BEGIN INIT INFO
# Provides: tomcat
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Should-Start: distcache
# Short-Description: start and stop Apache HTTP Server
# Description: implementation for Servlet 2.5 and JSP 2.1
## END INIT INFO
 
# Source function library.
/etc/init.d/functions
 
## tomcat installation directory
PROCESS_NAME=tomcat-servicename
 
CATALINA_HOME="/home/lesstif/apache-tomcat-7.0.54/"
 
## run as a diffent user
TOMCAT_USER=lesstif
 
##  Path to the pid, runnning info file
pidfile=${PIDFILE-/var/run/${PROCESS_NAME}.pid};
lockfile=${LOCKFILE-/var/lock/subsys/${PROCESS_NAME}};
 
RETVAL=0
 
case "$1" in
 start)
        PID=`pidofproc -p ${pidfile} ${PROCESS_NAME}`
        if [[ (-n ${PID}) && ($PID -gt 0) ]]; then
                logger -s "${PROCESS_NAME}(pid ${PID}) is  already running."
                exit;
        fi
        if [ -f $CATALINA_HOME/bin/startup.sh ];
          then
            logger -s "Starting Tomcat"
            /bin/su -l ${TOMCAT_USER} -c "$CATALINA_HOME/bin/startup.sh -Dprocessname=${PROCESS_NAME}"
            PID=`ps -eaf|grep processname=${PROCESS_NAME}|grep -v grep|awk '{print $2}'`
            RETVAL=$?
            [ $RETVAL = 0 ] && touch ${lockfile}
            [ $RETVAL = 0 ] && echo "${PID}" > ${pidfile}
        fi
        ;;
 stop)
        PID=`pidofproc -p ${pidfile} ${PROCESS_NAME}`
        ## if PID valid run shutdown.sh
        if [[ -z ${PID} ]];then
            logger -s "${PROCESS_NAME} is not running."
            exit;
        fi
 
        if [[ (${PID} -gt 0) && (-f $CATALINA_HOME/bin/shutdown.sh) ]];
          then
            logger -s "Stopping Tomcat"
            /bin/su -l ${TOMCAT_USER} -c "$CATALINA_HOME/bin/shutdown.sh"
            RETVAL=$?
            [ $RETVAL = 0 ] && rm -f ${lockfile}
            [ $RETVAL = 0 ] && rm -f ${pidfile}
        fi
        ;;
 status)
        status -p ${pidfile} ${PROCESS_NAME}
        RETVAL=$?
        ;;
 restart)
         $0 stop
         $0 start
         ;;
version)
        if [ -f $CATALINA_HOME/bin/version.sh ];
          then
            logger -s "Display Tomcat Version"
            /bin/su -l ${TOMCAT_USER} -c "$CATALINA_HOME/bin/version.sh"
            RETVAL=$?
        fi
        ;;
 *)
         echo $"Usage: $0 {start|stop|restart|status|version}"
        exit 1
        ;;
esac
exit $RETVAL


출처 : https://www.lesstif.com/pages/viewpage.action?pageId=6979609



conf/web.xml 파일에 다음과 같이 추가


<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app>

...

...

 

  <!-- error page setup -->
 <error-page>
  <error-code>404</error-code>
  <location>/error/code404.jsp</location>
 </error-page>


 <error-page>
  <error-code>500</error-code>
  <location>/error/code500.jsp</location>
 </error-page>

...

...

</web-app>

 

 

설정하고 나서 code404.jsp , code500.jsp 페이지를 해당디렉토리에 만든다.

JSP 스크립트립 부분은 제외하고 나머진 알아서 디자인 하면된다.

 

code404.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%

response.setStatus(HttpServletResponse.SC_OK);

%>
<html>
<head>
<title>404 에러 페이지</title>
</head>
<body>
요청하신 페이지는 존재하지 않습니다.
</body>
</html>

 

code500.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

<%

response.setStatus(HttpServletResponse.SC_OK);

%>    
<html>
<head>
<title>500 에러 페이지</title>
</head>
<body>
서비스 과정에서 에러가 발생했습니다.<br>

빠른 시일안에 문제를 해결하겠습니다.
</body>
</html>

 

 

에러 발생 후 처리 예제

예) 로그인시 해당 아이디를 가진 사용자의 이름을 파싱하지 못하는 에러 발생.

 

infoForm.html


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<form method="post" action="viewInfo.jsp">
 이 름 : <input type="text" name="name" size="20"> <br>
 나 이 : <input type="text" name="age" value="20"> <br>
<hr>
* P.S : 나이는 숫자만 입력해야 합니다. 
<hr>
<input type="submit" value="전송">
</form>

</body>
</html>

 

viewInfo.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page errorPage="error02.jsp" %>
<%! 
String s_name; 
int age;

%>   
<%
//post 전송 방식일 경우 파라메터에 대한 한글 처리
request.setCharacterEncoding("UTF-8");

s_name = request.getParameter("name");
age = Integer.parseInt(request.getParameter("age"));

%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3> 회원 정보 출력 </h3><hr>
당신의 이름은 <%= s_name %>입니다.<br>
당신의 나이는 <%= age %>살입니다.<br>
</body>
</html>

 

error02.jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page isErrorPage="true"%>   
<% 
response.setStatus(HttpServletResponse.SC_OK);
%>     
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<table align="center">
<tr bgcolor="#aaaaaa">
다음과 같은 에러가 발생하였습니다
</tr>
<tr>
<%= exception.getMessage() %>
</tr>
<table>
</body>
</html>

 [출처] http://www.cyworld.com/everysons/2352294

+ Recent posts