*
The moose likes JSP and the fly likes Why can't I get the Vector value in jsp(ModalDialog)? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Why can Watch "Why can New topic
Author

Why can't I get the Vector value in jsp(ModalDialog)?

lyo Yashnoo
Ranch Hand

Joined: Sep 15, 2003
Posts: 50
Hi everyone:
I am writing a E-mail system using javamail and I expect the user can add attachment to their mail.Add client can attach several attachments. So I write two pages,one is jsp:

<%Vector v=new Vector();session.setAttribute("allfiles",v);String file=request.getParameter("upfile");if(null!=file){ v.add(file); session.setAttribute("allfiles",v);}for(Enumeration e=v.elements();e.hasMoreElements() {out.println("File:"+e.nextElement().toString());}%><a href="#" o n c l ick="window.showModalDialog('addfile.html','Title','status:no;dialogHeight:320px;resizable:no');">Add</a>
Another is html:
<SCRIPT LANGUAGE="JavaScript"><!--function send(){alert("hello");opener.document.location="t.jsp"; self.close();}//--></SCRIPT></head><body><form action="t.jsp" name="uploadform" ENCTYPE="multipart/form-data">select File:<input type="file" name="upfile"/><INPUT TYPE="button" o n c lick="send()" value="sendToParent"/></form>
vector will get all the file and will be send to a servlet finally.
When user click "Add",it will open a ModalDialog that user can choose file.After choose file user click the button "sendToParent",the child window will close and the file name will send to t.jsp.
So t.jsp will add the value to the Vector and display it.
But when I click button after choose file the t.jsp display nothing. : (
Why the Vector can't get the value ( file path in the disc)? There is any error in my code ? Help!
Thks! :roll:
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
So t.jsp will add the value to the Vector and display it???
You are not submitting a form so you can not pass a value back and then request it. You need to rethink what you are trying to do here.
You can just rely on javascript to add it to a form field on tha parent page and have it hidden.
Plus Modal Wiondows is IE only...
Eric
Anselm Paulinus
Ranch Hand

Joined: Sep 05, 2003
Posts: 389
Iyo:
Your program should work, but then you have to remove the onclick event on the button tag, it is redundant.
2) You can not get the file object on the html by calling getParameter(); that is basically why you are having null value right now on the display at t.jsp. Use request.getInputStream() or request.getReader() to extract the file value. Also add a post method to the form parameter. Sending html parameters with get is going to be an eye sore; though it is doable.
Since you are actually setting the vector parameter in a session you should be alright.
I hope this helps.
Anselm
[ January 18, 2004: Message edited by: Anselm Paulinus ]
lyo Yashnoo
Ranch Hand

Joined: Sep 15, 2003
Posts: 50
Hi:
I change the code to:

It can work.It will add an item to Vector after I click button.But the new problem is that it will also add item to Vector when the user refresh the page!
I means that when I refresh the jsp page the item will add one.
How to avoid this situaction?
THks!
Anselm Paulinus
Ranch Hand

Joined: Sep 05, 2003
Posts: 389
Iyo:
You can not perform a test of null==v with a vector. You should rather do something like v.isEmpty() because vector is a collection.
2ndly, as I stated before you can not obtain a file object with getParameter(). If it works for you good, but I do not see that working, rather you should use one of the two commands I gave you earlier on.
As per the data been updated on refresh; I wont be able to comment on that right now. Javascript gurus should help out here.
bye,
Anselm
lyo Yashnoo
Ranch Hand

Joined: Sep 15, 2003
Posts: 50
Hi
Thks for your reply
I change the code to
"if(v.isEmpty)" but I get a nullpointer Exception when I first run the jsp.
I change two file to jsp.They are all jsp file.It also can't work property.
I think I will say the my main meaning:
I am writing a email system using javamail.I want to implement file upload in my mail system.I also want to user can upload many file.So I place a vector value in jsp page.When user add a file name the vector will add one.The Vector will send to servlet after user upload all files.
But I come across two problems:
1: how to add a hyperlink to the mail attachment? Because the attachment is stored in the mail server so I don't know how to get it.What I only can get is a inputstream.It is the attachment's inputstream support by javamail API.
But how to change the attachment's inputstream to a File So when user click it the attachment will be download?
2.I change the code ,but when I refresh the page vector will add one
Mybe javascript can solve it?
Help!
Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
Any idea? Help!


When I face C# and Java I choose Java.
Anselm Paulinus
Ranch Hand

Joined: Sep 05, 2003
Posts: 389
If you can paste your latest code on the screen, it might help.
Yashnoo lyo
Ranch Hand

Joined: Feb 17, 2003
Posts: 152
Ok
All code is:
///////////////////////////t.jsp//////////////////////////////////

////////////////////////////////addfiles.html//////////////////////////////

In my servlet I using the code get the Vector:

What is the important problem is that when user refresh the jsp ,the Vector will be added one object. How to avoid this happen?
lyo Yashnoo
Ranch Hand

Joined: Sep 15, 2003
Posts: 50
Hi friends.

I want to implement the Hotmail's function. Does anyone use hotmail? You can add many attachment to one mail. And it can add the value(file's path) to a table ,finally,it send the table's data to server. Can jsp do this?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why can't I get the Vector value in jsp(ModalDialog)?