Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Html textarea

Posted on 2006-06-16
10
Medium Priority
?
711 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 800 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 1200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

I’m willing to make a bet that your organization stores sensitive data in your Windows File Servers; files and folders that you really don’t want making it into the wrong hands.
How do you create a user-centered user experience on your website? And what are some things you should consider in the process?
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

564 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