aspose file tools*
The moose likes Servlets and the fly likes Urgent problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Urgent problem" Watch "Urgent problem" New topic
Author

Urgent problem

Sumit Israni
Greenhorn

Joined: Jun 20, 2001
Posts: 28
Hey Friends,
I am developing a File Upload servlet (yet another one )and I need your help in certain matters .I have taken the servlet code from java-edge.com and am modifying it to give custom behaviour.I have a main page for upload (form upload)(lets call it form 1).If the file to be uploaded already exists on the server then a page is generated by the server saying that file already exists.(form 2)Now it is here(in form 2) that I want to provide an extra button which when submitted would recall the same servlet /or maybe another one and would provide the user for overriding the existing file.
Now as per the code I would set the Override flag to be false in the second form and false in the main form .
Given the case that it is a form based uploading servlet how do I maintain the user session when going to the next form or how do i pass the variables of the first form into second form .
I am also facing another problem that is how do i manage multiple file uploads at a time .This basic system allows only one file per upload .
I hope I have explained my situation ..kindly let me know for clarifications.Thanks a lot
P.S If someone could also throw some light on how to use the com.oreilly servlet (the latest version) it would be lovely but for now I want to focus on developing the current one

Sumit Israni
Greenhorn

Joined: Jun 20, 2001
Posts: 28
Correction please :
Override flag false in the main form (Form1)and true in the second form(Form2)
Michael Arnett
Ranch Hand

Joined: Mar 22, 2001
Posts: 65
I'm not sure if I understand exactly what you are trying to do, and I am certain that this is probably not the best way to accomplish it , but I would try to use a Java Bean. Give it a "lifetime" of session, give it attributes that are relevant to your situation, and then these attributes would be available from all your pages.
Each of your pages would have the following usebean tag included in them:
<jsp:useBean id="SessionBeanId" scope="session" class="SessionBean" />
which would allow access to the Java Bean and (more importantly) its attributes.
Hope this is helpful, or if not let me know either what needs clarification or why this is irrelevant .
-MLA

Sun Certified Programmer for the Java 2 Platform 1.4
Sumit Israni
Greenhorn

Joined: Jun 20, 2001
Posts: 28
Hi Michael,
Thanks for your prompt response.I think you got what I tried to convey and that is probably the one of the right solutions.However there are a few problems from my end.
1)I dont know Beans,yes maybe its high time I know them in and out .
2)I am seriously constrained by time limitations ..and another aspect which is there is that the current File Upload is kinda working fine so I would like to hold myself to it as much as I could and
get the changes done on the same if possible.
I would appreciate it if you tell me how my current approach is not appropriate.
I however do feel it could be possible via servlets and passing hidden variables from one form to another ,but how that is to be achieved I dont know .Well thats just my guess!!
P.S:I would like to add here that the File Upload servlet is taken as is from www.java-edge.com with hardly any modifications
by me.
Thanks a lot Michael.
Sumit Israni
Greenhorn

Joined: Jun 20, 2001
Posts: 28
Hey Folks,
Your help is urgently required.Does anyone have a solution to the above problem!!I am at pains to find a solution as to how session tracking could be achieved in the above example .The getParameter() method does not work here .So i dont know how to go ahead .
Any help would be greatly appreciated.
Thanks a lot
Michael Arnett
Ranch Hand

Joined: Mar 22, 2001
Posts: 65
To utilize a bean is quite easy (without even changing your current solution dramatically). You would just create a java class that has a public default constructor and has a public getx and a public setx method for each class attribute x. For example:
public class SessionBean
{
String userName = "";

public SessionBean() {}

public String getUserName () { return userName; }
public void setUserName (String _name) { userName = _name; }
}
There's a bean class, then if you just use the usebean tag as I described and the setproperty and getproperty tags (there's plenty of free jsp references online for these tags) you can utilize your current solution and just incorporate a very simple bean for 'carrying' the relevant data between pages. Also, another handy point: If a form is submitted to a jsp page with this bean the following tags will set all class attributes which have the same name as input fields in the form...In this case userName would be given the value of a textbox whose name is userName also if the form's action was set to a jsp page with the following tags:
<jsp:useBean id="SessionBeanId" scope="session" class="SessionBean" />
<jsp:setProperty name="SessionBeanId" property="*" />

Hope this clarifies some of the bean things....
-MLA
PS If you really do not want to use beans, then you could always stick with hidden input fields which repetitively hold the value of the main form's fields (in other words every form has hidden input fields which inherit the values from the previous form or is updated by javascript or something).
Sumit Israni
Greenhorn

Joined: Jun 20, 2001
Posts: 28
Hi Michael,
Thanks a lot for the prompt response.I will be trying the suggested solution ,however I am wondering if at all a workaround to the problem exists in Javascript .I doubt so because Javascript cannot set the <INPUT TYPE =FILE> to a default value as taken from the hidden variable.If there is any other way of doing it,as you were suggesting of inheriting the hidden variables,can you post a sampler code as to how that would be achieved.As you know there are 2 html forms.The main one with the Overwrite flag set to false and the second form with its OverWrite flag set to true for providing the user to override the file if it already exists in the 1st session.I also dont think this can be achieved using Sessions as they too would require the getParameter method for extracting the value of hidden variables.
I earnestly look forward for your response.Thanks a million.
Regards
Michael Arnett
Ranch Hand

Joined: Mar 22, 2001
Posts: 65
In pseudo html form1 would look like:
<FORM>
<INPUT type=text name=filename >

form2 would be:
<FORM name=frmForm2>
<INPUT type=hidden name=filename value="<% out.println(request.getParameter("filename")) %>">
<INPUT type=hidden name=flag value = "false">
<INPUT type=button name=Overwrite onClick="setOverWrite();">
<INPUT type=submit name=submit>
<javascript>
function setOverWrite()
{
document.frmForm2.flag.value="true";
}

Roughly that would be a way to copy the values of any field to countless other html pages. Each following page would have the hidden flag and filename fields and would copy the value of the requests values (filename and flag) into their local hidden fields (filename and flag)...
Hope that helps!
-MLA
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Urgent problem