블로그 이미지
헤이장

Notice

Recent Post

Recent Comment

Recent Trackback

calendar

1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31
  • total
  • today
  • yesterday

'분류 전체보기'에 해당되는 글 18건

  1. 2009.07.27 [STRUTS2] 파일 업로드 (FileUpload)
  2. 2009.07.27 TEXT 폼 엔터처리
  3. 2009.07.20 SET 연산자 - 집합
2009. 7. 27. 12:58 Web/Framework

 struts.xml
   <action name="fileUpload" class="action.UploadAction">
   <interceptor-ref name="prepare" />
   <interceptor-ref name="modelDriven" />
   <interceptor-ref name="fileUpload" />
   <interceptor-ref name="params" />
   <interceptor-ref name="workflow" />
   <result>list.jsp</result>
  </action>

 struts.properties
// 멀티파트 파서. cos, pell, jakarta를 지정할 수 있다
struts.multipart.parser = jakarta
// 임시 저장 디렉토리. 디폴트로 javax.servlet.context.tempdir를 사용
struts.multipart.saveDir = /tmp
// 업로드 최대크기
struts.multipart.maxSize = 100000000

 Form.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!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=EUC-KR">
</head>
<body>
<form action="fileUpload.action" method="post" enctype="multipart/form-data">
이름 : <input type="text" name="name"/><br/>
나이 : <input type="text" name="age"/><br/>
이메일 : <input type="text" name="email"/><br/>
사진 : <input type="file" name="doc"/><br/>
<input type="submit" value="send"/>
</form>

</body>
</html>


 UploadAction.java

package action;

import java.io.File;

import org.apache.commons.io.FileUtils;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.opensymphony.xwork2.Preparable;

@SuppressWarnings("serial")
public class FileUploadAction extends ActionSupport implements Preparable, ModelDriven<User>{
 private final String UPLOAD_DIR = "e:/upload/"; // 저장할 디렉토리
// doc 파일 객체로부터 ContentType 과 FileName 을 얻어준다.
// ContentType과 FileName은 반드시 doc(파일객체명)로 시작해야한다
 File doc;
 String docContentType;
 String docFileName;
 User user; // 파일 객체 외의 정보도 받을 수 있다
 File savedFile;
 
 public String execute() throws Exception {
  if (doc != null && doc.exists()) {
   savedFile = new File(UPLOAD_DIR + docFileName); // 저장될 경로
   FileUtils.copyFile(doc, savedFile); // commons.io 로 파일 업로드 처리
  }
  return SUCCESS;
 }

 // SETTER
 public void setDoc(File doc) {
  this.doc = doc;
 }

 public void setDocContentType(String docContentType) {
  this.docContentType = docContentType;
 }

 public void setDocFileName(String docFileName) {
  this.docFileName = docFileName;
 }

 // GETTER
 public File getDoc() {
  return doc;
 }

 public User getUser() {
  return user;
 }

 public File getSavedFile() {
  return savedFile;
 }

 @Override
 public void prepare() throws Exception {
  user = new User();
 }

 @Override
 public User getModel() {
  return user;
 } 
}


posted by 헤이장
2009. 7. 27. 10:04 Web/JavaScript
키가 눌러질때마다 이벤트를 발생시켜 엔터 키 여부를 확인한다
엔터에 대한 keyCode 는 13

1. HTML 에서 자바스크립트 처리

function enterSubmit() {
 alert("enter");
}

<input type="text" onkeypress="if(event.keyCode == 13) {enterSubmit();}"/>

2. 자바스크립트에서 발생한 이벤트로 처리

function chkEnter() {
 if(event.keyCode == 13) {
  alert("enter");
 }
}

<input type="text" id="tf2" onkeypress="chkEnter()"/>

'Web > JavaScript' 카테고리의 다른 글

window.open 자바스크립트로 창 열기  (0) 2009.08.14
posted by 헤이장
2009. 7. 20. 14:46 Web/DB


*필드의 갯수와 자료형이 같아야한다

※ UNION - 합집합 (공통부분 제외)

select emp.employee_id, emp.first_name, emp.last_name from employees emp, departments dep, locations loc
where emp.department_id = dep.department_id and dep.location_id = loc.location_id and loc.country_id = 'DE'
union
select employee_id, last_name, last_name from employees
where job_id = 'AD_VP' ORDER by employee_id desc;

< 결과 >

204 Hermann Baer
102 De Haan De Haan
101 Kochhar Kochhar

※ UNION ALL - 합집합 (공통부분 모두)

※ INTERSECT - 교집합

※ MINUS - 차집합

posted by 헤이장