[struts web.xml 참조하기]
ServletConfig config = this.getServlet();
String configStr = config.getInitParameter("config");
System.out.println("configStr: " + configStr);
[struts web.xml 참조하기]
ServletConfig config = this.getServlet();
String configStr = config.getInitParameter("config");
System.out.println("configStr: " + configStr);
jar cvf ..\examples.war *
<Host appBase="D:\WebRoot\study" autoDeploy="true" name="localhost" unpackWARs="true" xmlNamespaceAware="false" xmlValidation="false">
[ 자동 리로드 ]
C:\tomcat-5.5.17\conf\Catalina\localhost\ROOT.xml
<Context path="" docBase="D:\WebRoot\study\ROOT" debug="0" reloadable="true" crossContext="true"/>
컨텍스트 이름별로 xml파일을 만든다.
[ 환경설정 ]
JAVA_HOME
CATALINA_HOME
CLASSPATH
import javax.servlet.ServletConfig;
import javax.servlet.http.HttpServlet;
public class CLASSNAME extends HttpServlet{
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public FUNCTION(){
javax.servlet.ServletContext servletContext = getServletContext();
}
}
ServletContext를 사용하기 위해선 init 메소드에서 super.init(config)를 해줘야한다.
(이유는 잘 모르겠다. 그에 답은 :http://okjsp.pe.kr/seq/40698)
ServletContext 객체를 얻을 수 있는 메서드는 HttpServlet 클래스의 getServletContext()이다.
(엄청 해깔린다. 이런식으로 ServletContext 의 servletContext 를 파라미터로 보내서 사용하면 좋을듯 싶다.
isELIgnored="false" jstl 사용함
request.setCharacterEncoding("euc-kr"); 한글 form 넘어온거
Properties 를 한번 사용할려고 여기저기, 자료를 찾을려고 기웃거려 봤는데..
워낙, 초보적인 내용이었는지.. 정리된것이 없더군요.
제가 가지고 있는 소스에 관련된 부분이 있어서.. 여기에 올립니다.
저초럼, 초보인 분에게 작은 도움이 될것 같아 올려봅니다.
......
간단히, 소스를 설명하자면..
PropertiesTest 실행할때
test.properties 라는 프로퍼티 파일을 가져오는데..
argument 가 있으면, test.properties 의 name 에 해당하는 value 를 불러오는거구요..
argument 가 없으면, test.properties 이의 프로퍼트에 value 을 변경시켜주는겁니다.~
test.properties 는 'PropertiesTest' class 가 있는 같은 디렉토리 위치에 있어야 겠지요.~
//===============================================================
//PropertiesTest.java
//===============================================================
import java.util.*;
import java.io.*;
class PropertiesTest {
public static void main(String[] args) throws IOException {
Properties props = new Properties();
if ( args.length == 0 ) {
props.put("Name", "홍길동");
props.put("Address", "Korea");
props.store( new FileOutputStream("test.properties"), "My Comment");
} else {
props.load( new FileInputStream("test.properties") );
}
System.out.println( "Name: " + props.getProperty("Name") );
System.out.println( "Address: " + props.getProperty("Address") );
}
}
//===============================================================
//test.properties
//===============================================================
#My Comment
Name=evergreen
Address=Korea
[Request 객체]
요청 피라미터 관련 메소드
String getParameter(String name) 피라미터의 값을 읽는다
String[] getParameterValues(String name) 체크박스 같은 복수의 값을 배열로 읽는다
getRemoteAddr() 아이피 얻기
request.setCharacterEncoding("euc-kr"); 한글
HTTP 헤더 관련 메소드
String getRemoteHost() 클라이언드 이름 얻기
String getRemoteAddr() 클라이언트 IP주소 얻기
Date() -> String 타입
Date date1 = new Date();
String test = date1.toString();
날짜 변환 예제
<%@ page import = "java.text.DateFormat" %>
<%@ page import = "java.text.SimpleDateFormat" %>
<%@ page import = "java.util.Date" %>
Date date1 = new Date();
long time1 = date1.getTime();
long time2 = 1152393007234L;
// long 타입 시간을 문자열 날짜&시간으로 구하기
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm");
String strDate = df.format(time1);
// 문자열로 구해진 날짜&시간 Date() 타입으로 변경하기
DateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm");
Date birthDay = sdFormat.parse(strDate);
int(long) -> String 변환
Date nowDate = new Date();
long test = nowDate.getTime();
String test1 = Long.toString(test); // int 일경우 Integer.
String -> long 변환
long tet = Long.parseLong(long 타입 값);
파일 이동
File fileMove1 = new File(request.getRealPath("/") + "board/pds/" + fileName);
File fileMove2 = new File(request.getRealPath("/") + "board/pds/" + tab + "/" + fileName);
fileMove1.renameTo(fileMove2);
[ 올림/반올림/자름 ]
Math.ceil(double) 무조껀 올림
Math.floor(double) 무조껀 자름
Math.round(double) 반 올림