Solved

Html textarea

Posted on 2006-06-16
10
703 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
This article provides a convenient collection of links to Microsoft provided Security Patches for operating systems that have reached their End of Life support cycle. Included operating systems covered by this article are Windows XP,  Windows Server…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 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