Solved

Html textarea

Posted on 2006-06-16
10
701 Views
Last Modified: 2007-10-18
HI,

I have a html form with a textarea, I am submitting this form to a jsp page. I would like to get at the contents of the textare in the jsp page and save to a file on the server.

Any ideas?

Thanks.
0
Comment
Question by:wilflife
  • 5
  • 3
  • 2
10 Comments
 
LVL 4

Expert Comment

by:pablomorales
ID: 16920233
Just make sure the method for the form is set to post. Assuming your form has a filename and an html field you could use the following code to save the file on the server:

<%@page language="java" %><%

String filenameName=request.getParameter("filename");
String headerSize=request.getParameter("html");

PrintWriter file = new PrintWriter(  application.getRealPath( filename );
css.print(html);
css.close();

%>
<html>
<head>
<title>File saved</title>
</head>
<body>
Your file has been saved.
</doby>
</html>

I would avise you to be carefull about how you give access to this page because it pretty much allows them to change anything in your site.
0
 
LVL 4

Expert Comment

by:pablomorales
ID: 16920251
There are a couple of errors on the previous post. This is the corrected code:

<%@page language="java" %><%

String filenameName=request.getParameter("filename");
String headerSize=request.getParameter("html");

PrintWriter file = new PrintWriter(  application.getRealPath( filename ) );
file.print(html);
file.close();

%>
<html>
<head>
<title>File saved</title>
</head>
<body>
Your file has been saved.
</doby>
</html>
0
 

Author Comment

by:wilflife
ID: 16920482
No luck using the form i have here.

What do you mean assuming it has a filename and html tag?
Thanks.
My form.

<form method="post" ACTION="http://servlet/file.jsp" name="upform" ENCTYPE='multipart/form-data'>
<input type="file" name="uploadfile">
<p>
<input type="textarea" name="textarea" style="display:none;">
<input type="submit" name="Submit" value="Submit" style="display:none;">
<input type="hidden" name="action" value="upload">

</form>
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 4

Expert Comment

by:pablomorales
ID: 16920597
Looking at your form I see that what you are trying to upload a file. That can be acomplished with this taglib:

http://www.servletsuite.com/servlets/uptag.htm
0
 
LVL 4

Expert Comment

by:pablomorales
ID: 16920747
Here is another taglib that you can use and that is not restricted by size but that is a little more complicated to use:

http://www.xephyrus.com/taglib-fileupload/

Here is some sample code:

<%@ taglib uri="/jstl-c"                prefix="c" %>
<%@ taglib uri="/xephyrus-fileupload"   prefix="fup" %>

<%-- prepare the page --%>
<!DOCTYPE html PUBLIC
  "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title>
      A Simple JSP Example for the Xephyrus File Upload Tag Library
    </title>
    <link rel="stylesheet" href="stylesheet.css" type="text/css" />
  </head>
  <body>
    <div align="center">
      <table width="80%"><tr><td>
        <div class="title">
          Xephyrus File Upload Tag Library<br />
          Image Upload Example
        </div>

        <p>
          This example presents a form to upload a jpeg image and a caption.
          After the image has been uploaded, it will be displayed below.
        </p>

        <form method="POST" action="example.jsp" enctype="multipart/form-data">
          <p align="center">
            JPEG Image to Upload:
            <input type="file" name="up" accept="image/jpeg" />
            <input type="submit" name="upload" value="Upload" />
          </p>
        </form>

        <p>
          <%-- parsing must happen before any parameters can be accessed --%>
          <fup:parse nonUpload="ignore" />
        </p>
        <c:if test="${!empty pageScope.param.upload}">
          <fup:file var="one">
            <div align="center" class="presented">
              Field Name:
              <fup:name item="one" /><br />

              Content-Type:
              <fup:contentType item="one" /><br />

              Size:
              <%-- if you're in a 'file' body, 'item' is not needed --%>
              <fup:size /><br />

              Remote Path:
              <fup:remotePath /><br />

              Local Path:
              <fup:localPath /><br />

              <%-- the '~' means 'the file path to this jsp'
                   the output of write is the new path
                   you can assign it to a junk var with something like
                  <fup:write to="~/uploaded.jpg" var="silent" />
              --%>
              Final Path:
              <fup:write to="~/uploaded.jpg" /><br />

              <img src="uploaded.jpg" alt="Uploaded Image" />
            </div>
          </fup:file>
        </c:if>

      </td></tr></table>
    </div>
  </body>
</html>

0
 

Author Comment

by:wilflife
ID: 16921040
Thanks i should have cut the file upload out.

I have to do it from a textarea as i am building the xml file dynamically.

So i have to do it from a teaxtarea.

My apologies for keeping that in.

Still trying with your original technique.

Still uncertain by what you mean:

Just make sure the method for the form is set to post. Assuming your form has a filename and an html field you could use the following code to save the file on the server:

0
 

Author Comment

by:wilflife
ID: 16921933
I have cut your code right down, and my form is as as follows i can't access the properties of the form at all in the jsp. Am i missing something obvious?

<form method="post" ACTION="http://servlet/ftest.jsp" name="upform" ENCTYPE='multipart/form-data'>
<p>
<input type="textarea" name="textarea" value="Find in Jsp">
<input type="submit" name="Submit" value="Submit">
<input type="hidden" name="action" value="upload">

</form>

So i took your original code and stripped it right down to the parameter search and i just get null returned.

<%@page language="java" %><%

String filename=request.getParameter("upform.textarea"); // also tried request.getParameter("textarea");

out.println("Try to get text area" + filename);


%>

No luck whatsoever.

Thanks for any help.
0
 
LVL 4

Assisted Solution

by:pablomorales
pablomorales earned 200 total points
ID: 16922190
I meant that the form method is POST (as it is). Don't worry about the fields, now that I can see your form I know what your field names are.  This should work:

<%@page language="java" %><%

String filename="file.xml"; // change this to whatever you wan the file to be named
String data=request.getParameter("textarea");

PrintWriter file = new PrintWriter(  application.getRealPath( filename ) );
file.print(data);
file.close();

%>
<html>
<head>
<title>File saved</title>
</head>
<body>
Your file has been saved.
</doby>
</html>
0
 
LVL 11

Accepted Solution

by:
Manish earned 300 total points
ID: 16926249
As your encrypt is ENCTYPE='multipart/form-data' so you need something like this.

http://www.experts-exchange.com/Web/Web_Languages/JSP/Q_21147702.html

karan
0
 
LVL 11

Expert Comment

by:Manish
ID: 16934235
:)
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This tutorial shows how to create a greeting card by combining two image layers and a text layer on a PC using a free image editing app.
An article on effective troubleshooting
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question