Solved

Html textarea

Posted on 2006-06-16
10
698 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Short answer to this question: there is no effective WiFi manager in iOS devices as seen in Windows WiFi or Macbook OSx WiFi management, but this article will try and provide some amicable solutions to better suite your needs.
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

11 Experts available now in Live!

Get 1:1 Help Now