• Post Reply Bookmark Topic Watch Topic
  • New Topic

Save form data to server hard disk via JSP

 
Rocky Tay
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there, I'm new to JSP. I hope to get help from anyone as i'm stuck with the problem for a long time.
<form action=" saveData.jsp"/>
Firstly, I have performed a form submit with a hidden value. I would like the value to be saved in a text file at server hard disk. I don't know what method to put in the saveData.jsp to get the hidden value and save to server hard disk. Thank you.

Rocky.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65524
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rocky Tay:

<form action=" saveData.jsp"/>
Firstly, I have performed a form submit with a hidden value.

What hidden value? There is none, and there can be none as you have self-closed the form tag.

Put the <input> element as a child of the <form>.
 
Vijitha Kumara
Bartender
Posts: 3952
21
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have performed a form submit with a hidden value


If you can post some code then people here will help you solve it.
 
Rocky Tay
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are the code:

<form name="SubmitToMain" method="post" action="GetInfo.jsp" onsubmit="return sendDocument()">
<input type="hidden" name="TextValue" value="">
<input type="submit">
</form>

The above code are the form to submit. I would like the value to be save in a text file at server hard disk. I don't know what method to put in GetInfo.jsp. The sendDocument() get the value from the text area, which is created in the applet. Thanks.
 
Rocky Tay
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have managed to create a file on the server side. I got this help from java forum user, citcru. What he wrote was to place the code in the servlet:

String tv = request.getParameter("TextValue");

FileWriter fw = new FileWriter(new File(path));
fw.write(tv);
fw.flush();
fw.close();

But, after I have managed to create the file, I found that the text file was empty. I suspect that the value was the root of the problem.
I shall place sendDocument() function code here:

<script language="JavaScript">
function sendDocument()
{


document.SubmitToMain.TextValue.value =
document.EncryptApplet.AppletPanel.getEncryptedText();

}
</script>

In the form, <input type="hidden" name="TextValue" value="" >.
document.EncryptApplet.AppletPanel.getEncryptedText() get the value of the text area of the applet. This side doesn't has any problem as I have done some testing.

Please give me a helping hand. It would be greatly appreciated.
Thank you.

Rocky.
 
Rocky Tay
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have managed to solve the problem. For those who need the solution, here are the code.
<script language="JavaScript">

function sendDocument()
{

document.SubmitToMain.elements["TextValue"].value=
document.EncryptApplet.getEncryptedText();
return true;
}

</script>
Previously, i placed it as document.SubmitToMain.TextValue.value. The document.SubmitToMain.elements["TextValue"].value is the main solution to not being able to get the value. With this, value can be saved in the server hard disk as text file.

Hope this provide helps to those facing this problem.

Rocky.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!