Solved

Html textarea

Posted on 2006-06-16
10
699 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
what is stuck threads? 3 97
form submissions on a web page 2 143
build fail in maven project 11 179
spring example errors 33 259
Scenario: Your operations manager has discovered an anomaly in your security system. The business will start to suffer within 15 minutes if it is a major IT incident. What should she do? We have 6 recommendations for managing major incidents (https:…
When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

895 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now