[질문]서블릿에서 파일과 파라미터를 같이 받으려면...


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]

글쓴이 :남 재범 1999년 4월 03일 18:56:12

서블릿을 통해 게시판을 판들고 있습니다. 화일 첨부와 다른 input 값들을 post로 받고 있는 중입니다.
여기 질문 할때랑 같은 모양의 게시판 모양으로요..
파일만 받을 때는 inputstram으로 받아서 가능한데,
이 때 같이 parameter, 즉 이름이나 제목 등을 파일과 같이 포스트로 보내려고 합니다.
파일 이름을 추출하는 것은 책(삼각형에서 나온 거)을 보고 해결 했는데,,
이 때 같이 넘어간 파일 이름 추출하는 방법을 도통..



파일 이름 추출 하는 부분을 같이 올립니다..


부디 살려주세요..
class parseMultiForm extends Object{

private DataInputStream in;
private String delimitor = null;
private boolean firstCall = true;
private String filename= null;


public parseMultiForm(InputStream In)
{
in = new DataInputStream(In);

try{
delimitor = in.readLine();
}catch(IOException E){
in = null;
}
}
String getDelimitor(){
return delimitor;
}


String getNextParameter(){
String paraname = null;
try{
String LineIn = null;

while((LineIn= in.readLine()) != null){

if(LineIn.indexOf("name=") != -1){

int s= LineIn.indexOf("name=");

int e= LineIn.indexOf("\"",s+6);

paraname= LineIn.substring(s+6,e);

if(LineIn.indexOf("filename=") != -1){
s= LineIn.indexOf("filename=");

e= LineIn.indexOf("\"",s+10 );

filename=LineIn.substring(s+10, e);

if(filename.lastIndexOf("\\")!= -1)
filename= filename.substring(filename.lastIndexOf("\\")+1);

if(filename.length() == 0)
filename = null;
}

LineIn = in.readLine();
if(LineIn.indexOf("Content-Type") != -1)
LineIn = in.readLine();

return paraname;
}
}//end while
}//end try
catch(Exception E){}
return null;
}



String getFileName(){
getNextParameter();

return filename;
}

boolean readParameter (OutputStream out){

byte buffer[]= new byte[1024];
byte tbuffer[] = new byte[delimitor.length()+3];
int x= 0;
byte charIn;

try {
for (;;) {
buffer[x++]= charIn = in.readByte();
if (x== delimitor.length()+3){

int y=0;

String temp = new String(buffer, 0,0,x);
if ((y=temp.indexOf(delimitor)) != -1) {
x= y;

if(x!= 0)
out.write(buffer, 0, x-1);
return true;
}
}
else{
if ((x==1023)||(charIn == '\n')){
out.write(buffer, 0,x);
x= 0;
}
}
}
}
catch(Exception E){
}
return false;
}
String readParameter(){
try{
return in.readLine();
}
catch(IOException E){}
return null;
}
}




다음 글들:



이어서 글올리기(답하기)

이름:
E-Mail:
제목:
내용:
HTML 태그 포함 여부: HTML 문서일 경우 체크
관련 URL(선택):
URL 제목(선택):
관련 이미지 URL:


[ 다음 글들 ] [ 이어서 글올리기(답하기) ] [ 자바 묻고 답하기 ]