파일명 : createForm_Test.jsp
-------------------------------------------
<%@ page contentType="text/html; charset=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">
<title>Insert title here</title>
</head>
<body>
<center>
글 등록


<form name='frmData'
      action='./createProc_Test.jsp'
      method='post'
      enctype="multipart/form-data" >
    제목: <input type='text' name='title' size='20'></input><br></br>
    내용: <textarea name="content" rows='5' cols="20"></textarea><br></br>
    참고: <input type='text' name='etc' size='20'></input><br></br>
   
    <input type='submit' value='등록'></input>
</form>

</center>
</body>
</html>
-------------------------------------------

 

파일명 : createProc_Test.jsp
-------------------------------------------
<%@ page contentType="text/html; charset=euc-kr" %>
<%
request.setCharacterEncoding("euc-kr");

//폼의 값을 가져옵니다.
String title   = request.getParameter("title");
String content = request.getParameter("content");
String etc     = request.getParameter("etc");
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=euc-kr" />
<title>등록 처리</title>

</head>

<body>
<center>
<h2>
<%
out.println("title: " + title);
out.println("content: " + content);
out.println("etc: " + etc);
%>
</h2>
<center>

</body>
</html>
-------------------------------------------

 

파일명 : StringTest.java
-------------------------------------------
package www.pds;

public class StringTest {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        // 1) 에러
        // String path="F:\www_jsp\doc\picture.jpg";
       
        // 2) windows 계열 경로 표현
        String win="F:\\www_jsp\\doc\\picture.jpg";
       
        // 3) linux, unix 계열
        String linux="F:/www_jsp/doc/picture.jpg";
       
        // 4) 폴더 구분자 '\'의 위치 출력
        int sp = win.indexOf("\\");
        System.out.println("\\의 위치: " + sp); // 2
       
        // 5) 마지막 폴더 구분자 '\'의 위치 출력
        sp = win.lastIndexOf("\\");
        System.out.println("\\의 마지막 위치: " + sp); // 14
          
        // 6) 순수 파일명 추출, 마지막 폴더 구분자 + 1
        String filename = win.substring(14+1);  
        System.out.println("1) 추출된 파일명: " + filename);
       
        // 7) 순수 파일명 추출 전용 코드
        filename = win.substring(win.lastIndexOf("\\"));  
        System.out.println("2) 추출된 파일명: " + filename);
        filename = win.substring(win.lastIndexOf("\\")+1);  
        System.out.println("3) 추출된 파일명+1: " + filename);
       
        // 8) Test
        win = "F:\\ImageCenter\\스위스\\sw01.jpg";
        filename = win.substring(win.lastIndexOf("\\")+1);  
        System.out.println("4) 추출된 파일명: " + filename);
       
        // 9) 폴더명만 추출
        String folder = win.substring(0, win.lastIndexOf("\\"));  
        System.out.println("5) 추출된 폴더명: " + folder);
       
        // 10) sw01만 추출할 것
        win = "F:\\ImageCenter\\스위스\\sw01.jpg";
        int start = win.lastIndexOf("\\");
        int end = win.indexOf(".");
        System.out.println("6) 추출된 순수 파일명: " + win.substring(start+1, end));

    }

}

+ Recent posts