doc: 테스트 jsp 파일 추가

dev
minkyu1128 2 years ago
parent 5313812031
commit b2dbca348a

@ -0,0 +1,46 @@
# 시작하기
***
배포환경에 따라 WAS 및 JDK 버전이 각기 다르며
이로인해 발생 할 수 있는 각종 오류들에 대한 원인을 파악하는데 있어
datasource 접속가능여부 및 기타 정보를 확인할 수 있는 jsp 파일을 제공 한다.
### 버전관리
|버전|작성일|작성자|내용|
|---|---|---|---|
|v0.1|2022.12.29|박민규|최초작성|
## 1. 배포하기
1. [**Tomcat 다운로드**](https://tomcat.apache.org/)
* 원하는 버전의 zip 파일 다운로드
2. **다운로드 파일 unzip**
3. **서버 기동하기** - *~/bin/startup.bat* 파일 실행
<mark>**\[ JDK 오류발생 시 처리방법 \]**</mark>
+ *~/bin* 경로에 **setenv.bat 파일 생성**
+ setenv.bat 파일에 **JAVA_HOME 작성**
+ set JAVA_HOME=[JDK 설치 경로]
+ ex) set JAVA_HOME=C:\XIT\java\corretto-11.0.15
4. **정상기동 여부 확인** - http://localhost:8080 으로 접속
+ 고양이 그림이 있는 Apache Tomcat 화면이 뜨면 성공
5. *~/webapps* 경로에 **"check" 디렉토리 복사**
6. **서버 재기동** - ~/bin/shutdown.bat & ~/bin/startup.bat
## 2. 테스트
1. 페이지 호출
+ http://localhost:8080/[파일명] //부록-파일 설명 참고
+ ex) http://localhost:8080/javaenv.jsp
<u>*DB 접속 테스트(datasource.jsp) 시*에는 ~/lib 경로에 *jdbc 라이브러리 파일(.jar)을 추가*</u>해야 한다.
# 부록
***
### 파일 설명
|File Name|Description|
|---|---|
|datasource.jsp|DB 접속 테스트|
|fontinfo.jsp|현재 플랫폼에서 사용가능한 폰트 목록 확인|
|hostname.jsp|호스트명 확인|
|javaenv.jsp|java 시스템 등록정보|
|urlcheck.jsp|URL 호출 테스트|

@ -0,0 +1,293 @@
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ page import="java.sql.*, javax.sql.*, javax.naming.*" %>
<%
request.setCharacterEncoding("UTF-8"); //2020.09.25. 박민규- 캐릭터셋 설정
String uri = request.getRequestURI();
String type = request.getParameter("type");
String dsNm = request.getParameter("dsNm");
String driver = request.getParameter("driver");
String url = request.getParameter("url");
String user = request.getParameter("user");
String password = request.getParameter("password");
String sql = request.getParameter("sql");
if( type == null || type.equalsIgnoreCase("null") ) type = "";
if( dsNm == null || dsNm.equalsIgnoreCase("null") ) dsNm = "";
if( driver == null || driver.equalsIgnoreCase("null") ) driver = "";
if( url == null || url.equalsIgnoreCase("null") ) url = "";
if( user == null || user.equalsIgnoreCase("null") ) user = "";
if( password == null || password.equalsIgnoreCase("null") ) password = "";
if( sql == null || sql.equalsIgnoreCase("null") ) sql = "";
String msg = "";
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
%>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>DataSource 확인</title>
<style>
body { font-family:sans-serif, arial; font-size:9pt; }
table { font-family:sans-serif, arial; font-size:9pt; }
</style>
<script language="JavaScript">
<!--
function setField() {
var check = document.dbinfo.type.value;
if( check == "direct" ) {
document.all["nondirect"].style.visibility = "hidden";
document.all["direct1"].style.visibility = "visible";
document.all["direct2"].style.visibility = "visible";
document.all["direct3"].style.visibility = "visible";
document.all["direct4"].style.visibility = "visible";
}
else {
document.all["nondirect"].style.visibility = "visible";
document.all["direct1"].style.visibility = "hidden";
document.all["direct2"].style.visibility = "hidden";
document.all["direct3"].style.visibility = "hidden";
document.all["direct4"].style.visibility = "hidden";
}
}
function checkFiled() {
if( document.dbinfo.type.value == "direct" ) {
if(document.dbinfo.driver.value == "") {
alert("Plaese Input Driver Name.(ex : oracle.jdbc.driver.OracleDriver)");
document.dbinfo.driver.focus();
return false;
}
else if(document.dbinfo.url.value == "") {
alert("Please Input DB URL.(ex : jdbc:oracle:thin:@dbip:dbport:dbsid)");
document.dbinfo.url.focus();
return false;
}
else document.dbinfo.submit();
}
else {
if(document.dbinfo.dsNm.value == "") {
alert("Please Input DataSource Name.(ex : jdbc/demo)");
document.dbinfo.dsNm.focus();
return false;
}
else document.dbinfo.submit();
}
}
function checkFiled2() {
if( document.dbinfo.sql.value == "" ) {
alert("Plaese Input SQL statment.");
document.dbinfo.sql.focus();
return false;
}
else {
document.dbinfo.submit();
}
}
//-->
</script>
</head>
<body style="margin:10" onload="setField()">
<h2>Check DataSource<h2>
<form name="dbinfo" method="post" action="<%= uri %>">
<table width="585" border="1" cellspacing="0" cellpadding="0" bordercolor="#808080" bordercolorlight="#C0C0C0" bordercolordark="#F6F6F6">
<tr height="20">
<td align="center" bgcolor="#C0C0C0" width="100">WAS 유형</td>
<td align="center" width="192">
<select name="type" onchange="setField()">
<option value="lookup" <%= type.equals("lookup")?"selected":"" %>>lookup</option>
<option value="nonlookup" <%= type.equals("nonlookup")?"selected":"" %>>nonlookup</option>
<option value="direct" <%= type.equals("direct")?"selected":"" %>>direct</option>
</select>
</td>
<td align="center" bgcolor="#C0C0C0" width="100">DataSource</td>
<td align="center" width="192">
<div id="nondirect" style="visibility:">
<input type="text" name="dsNm" size="20" value="<%= dsNm %>">
</div>
</td>
</tr>
<tr height="20">
<td align="center" bgcolor="#C0C0C0" width="100">Driver</td>
<td align="center">
<div id="direct1" style="visibility:hidden">
<input type="text" name="driver" size="20" value="<%= driver %>">
</div>
</td>
<td align="center" bgcolor="#C0C0C0" width="100">URL</td>
<td align="center">
<div id="direct2" style="visibility:hidden">
<input type="text" name="url" size="20" value="<%= url %>">
</div>
</td>
</tr>
<tr height="20">
<td align="center" bgcolor="#C0C0C0" width="100">User</td>
<td align="center">
<div id="direct3" style="visibility:hidden">
<input type="text" name="user" size="20" value="<%= user %>">
</div>
</td>
<td align="center" bgcolor="#C0C0C0" width="100">Password</td>
<td align="center">
<div id="direct4" style="visibility:hidden">
<input type="text" name="password" size="20" value="<%= password %>">
</div>
</td>
</tr>
</table>
<table width="585" border="0" cellspacing="0" cellpadding="0" bordercolor="#808080" bordercolorlight="#C0C0C0" bordercolordark="#F6F6F6">
<tr height="30">
<td align="center">
<input type="button" value="DB Connect Test" onclick="checkFiled()">
</td>
</tr>
</table>
<%
if( type.equals("lookup") || type.equals("nonlookup") || type.equals("direct") ) {
try {
if( type.equals("lookup") ) { //lookup type (Tomcat, resin, Jrun ...)
Context ctx = new InitialContext();
Context env = (Context)ctx.lookup("java:comp/env");
DataSource ds = (DataSource)env.lookup(dsNm);
conn = ds.getConnection();
}
else if( type.equals("nonlookup") ) { //nonlookup type (Jeus, WebLogic, WebSphere ...)
Context ctx = new InitialContext();
DataSource ds = (DataSource)ctx.lookup(dsNm);
conn = ds.getConnection();
}
else { //direct
Class.forName(driver);
conn = DriverManager.getConnection(url, user, password);
}
if( conn == null ) msg = "Connection Fail!!!";
else msg = "Connection Success!!!";
}
catch(Exception e) {
msg = e.getMessage();
}
finally {
%>
<table width="585" border="1" cellspacing="0" cellpadding="0" bordercolor="#808080" bordercolorlight="#C0C0C0" bordercolordark="#F6F6F6">
<tr height="20">
<td align="center" bgcolor="#C0C0C0">Result(<%= type %>)</td>
</tr>
<tr height="50">
<td align="center" valign="middle"><%= msg %></td>
</tr>
</table>
<%
if( conn != null ) {
%>
<br>
<table width="585" border="1" cellspacing="0" cellpadding="0" bordercolor="#808080" bordercolorlight="#C0C0C0" bordercolordark="#F6F6F6">
<tr height="20">
<td align="center" bgcolor="#C0C0C0">SQL</td>
</tr>
<tr height="50">
<td>
<textarea name="sql" rows="8" cols="80"><%= sql %></textarea>
</td>
</tr>
</table>
<table width="585" border="0" cellspacing="0" cellpadding="0" bordercolor="#808080" bordercolorlight="#C0C0C0" bordercolordark="#F6F6F6">
<tr height="30">
<td align="center">
<input type="button" value="Data View" onclick="checkFiled2()">
</td>
</tr>
</table>
<%
if( sql != null && !sql.equals("") ) {
%>
<table width="585" border="1" cellspacing="0" cellpadding="0" bordercolor="#808080" bordercolorlight="#C0C0C0" bordercolordark="#F6F6F6">
<%
try {
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
ResultSetMetaData rsmd = rs.getMetaData();
int cnt = rsmd.getColumnCount();
out.println("<tr>");
for(int i = 0; i <= cnt; i++) {
if( i == 0 ) out.println("<td bgcolor=\"#C0C0C0\" align=\"center\">No</td>");
else out.println("<td bgcolor=\"#C0C0C0\" align=\"center\">" + rsmd.getColumnLabel(i) + "</td>");
}
int row_cnt = 0;
while( rs.next() ) {
out.println("<tr>");
for(int i = 0; i <= cnt; i++) {
if( i == 0 ) out.println("<td align=\"center\">" + ++row_cnt + "</td>");
else out.println("<td align=\"center\">" + rs.getString(i) + "</td>");
}
out.println("</tr>");
}
if( row_cnt == 0 ) {
out.println("<tr height=\"100\"><td align=\"center\" colspan=\"" + (cnt + 1) + "\">조회 내역이 없습니다.</td></tr>");
}
}
catch(Exception ee) {
out.println("<tr><td bgcolor=\"#C0C0C0\" align=\"center\">Error Message</td></tr>");
out.println("<tr height=\"100\"><td align=\"left\" valign=\"top\">" + ee.getMessage() + "</td></tr>");
}
%>
</table>
<%
}
if( rs != null ) try{ rs.close(); rs = null; } catch (Exception ex) {}
if( ps != null ) try{ ps.close(); ps = null; } catch (Exception ex) {}
if( conn != null ) try { conn.close(); conn = null; } catch(Exception e) {}
}
}
}
%>
</form>
</body>
</html>

@ -0,0 +1,24 @@
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ page import="java.awt.*" %>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Font 정보</title>
<style>
body { font-family:sans-serif, arial; font-size:9pt; }
table { font-family:sans-serif, arial; font-size:9pt; }
</style>
<body>
<%
//System.setProperty("sun.java2d.fontpath", "font_location_path");
// System.setProperty("java.awt.headless", "true");
String[] fontNames = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
for (int i=0; i<fontNames.length; i++)
{
out.println(fontNames[i]+"<br>");
}
%>
</body>
</html>

@ -0,0 +1,19 @@
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ page import="java.net.*" %>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Hostname 확인</title>
<style>
body { font-family:sans-serif, arial; font-size:9pt; }
</style>
</head>
<body style="margin:10">
<h2>Hostname Check</h2>
Hostname : [<%= InetAddress.getLocalHost().getHostName() %>]<br>
AppPath : [<%= getServletContext().getRealPath("/") %>]
</body>
</html>

@ -0,0 +1,26 @@
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Java Environment 확인</title>
<style>
body {
font-size:10pt;
font-family: Arial;
color: #000000;
line-height:18px;
}
</style>
<body>
<%
java.util.Enumeration e = System.getProperties().propertyNames();
while(e.hasMoreElements()) {
String key = (String)e.nextElement();
if( key.indexOf("class.path") != -1 || key.indexOf("loader") != -1 ) out.print("<li><font color='red'>" + key + " : " + System.getProperty(key) + "</font></li>");
else out.print("<li>" + key + " : " + System.getProperty(key) + "<br>");
}
%>
</body>
</html>

@ -0,0 +1,134 @@
<%@ page contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ page import="java.net.*, java.io.*" %>
<%
String NL = System.getProperty("line.separator");
String sReqType = request.getParameter("req_type");
String sUrl = request.getParameter("url");
if( sReqType == null || sReqType.equalsIgnoreCase("null") ) {
sReqType = "GET";
}
if( sUrl == null || sUrl.equalsIgnoreCase("null") ) {
sUrl = "";
}
StringBuffer contents = new StringBuffer();
if( !sUrl.equals("") ) {
try {
URL url = new URL(sUrl);
contents.append(">> URL(" + sUrl + ") Connecting...").append(NL);
HttpURLConnection uc = (HttpURLConnection)url.openConnection();
uc.setDoOutput(true);
uc.setDoInput(true);
uc.setUseCaches(false);
uc.setRequestMethod(sReqType);
StringBuffer sb = new StringBuffer();
InputStream is = uc.getInputStream();
contents.append(">> Reading Contents...").append(NL);
BufferedReader in = new BufferedReader(new InputStreamReader(is));
int buffSize = 1024 * 8;
char[] buff;
int insize = 0;
while ((insize = in.read(buff = new char[buffSize], 0, buffSize)) != -1) {
sb.append((new String(buff, 0, insize)));
}
String receivestr = sb.toString().trim();
contents.append(">> Contents").append(NL);
contents.append("------------------------------------------").append(NL);
contents.append(sb.toString().trim()).append(NL);
contents.append("------------------------------------------").append(NL);
contents.append(">> End").append(NL);
}
catch(FileNotFoundException fnfe){
contents.append(">> FileNotFoundException").append(NL);
contents.append("------------------------------------------").append(NL);
contents.append(fnfe.getMessage()).append(NL);
contents.append("------------------------------------------").append(NL);
contents.append(">> End").append(NL);
fnfe.printStackTrace();
}
catch(Exception e){
contents.append(">> Exception").append(NL);
contents.append("------------------------------------------").append(NL);
contents.append(e.getMessage()).append(NL);
contents.append("------------------------------------------").append(NL);
contents.append(">> End").append(NL);
e.printStackTrace();
}
}
%>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>URL 확인</title>
<style>
body { font-family:sans-serif, arial; font-size:9pt; }
table { font-family:sans-serif, arial; font-size:9pt; }
</style>
<script language="JavaScript">
<!--
function checkURL() {
if(document.urlcheck.url.value == "") {
alert("Please Input URL(ex : http://localhost:8080)");
document.urlcheck.url.focus();
return false;
}
else document.urlcheck.submit();
}
//-->
</script>
</head>
<body style="margin:10">
<h2>Check URL<h2>
<form name='urlcheck' method='post' action='./urlcheck.jsp'>
<table width="585" border="1" cellspacing="0" cellpadding="0" bordercolor="#808080" bordercolorlight="#C0C0C0" bordercolordark="#F6F6F6">
<tr height="20">
<td align="center" bgcolor="#C0C0C0" width="100" style='padding:3px'>REQ TYPE</td>
<td align="left" style='padding:3px; padding-left:6px;'' >
<select name="req_type">
<option value="GET" <%= sReqType.equals("GET")?"selected":"" %>>GET</option>
<option value="POST" <%= sReqType.equals("POST")?"selected":"" %>>POST</option>
</select>
</td>
</tr>
<tr height="20">
<td align="center" bgcolor="#C0C0C0" width="100" style='padding:3px'>URL</td>
<td align="center" style='padding:3px'>
<input type="text" name="url" size="70" value="<%= sUrl %>">
</td>
</tr>
</table>
<table width="585" border="0" cellspacing="0" cellpadding="0" bordercolor="#808080" bordercolorlight="#C0C0C0" bordercolordark="#F6F6F6">
<tr height="30">
<td align="center">
<input type="button" value="URL CHECK" onclick="checkURL()">
</td>
</tr>
</table>
</form>
Result<br>
<textarea name="sql" rows="20" cols="84"><%= contents.toString() %></textarea>
</body>
</html>
Loading…
Cancel
Save