Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Web Tools Project (WTP) » JSP textarea
JSP textarea [message #168422] Wed, 03 May 2006 12:59 Go to next message
Ben Sisson is currently offline Ben Sisson
Messages: 202
Registered: July 2009
Senior Member
I created a JSP file that would take comments about my web service that i
created. I am having problems however retrieving the comments from the
textarea that they are entered into.

I create a textarea that they can enter the comments into:
<textarea name="NewComments" id="NewComments" rows="10" cols="100">
Your comments go
here.
</textarea>
<br />

I then try to retrieve the comments so that I can write them to a database.
<%
String value = request.getParameter("NewComments");
%>

I then try to write the comments out to verify that it worked (I have
tried several varyiations of this):
alert('<%= value %>');
alert(<%= value %>);

The only thing outputed is a "null" value.

Can someone pleas explain to me how to retrieve the text data from the
textarea within a HTML .jsp file?

On the other hand, I have no problem retrieving data from a database and
then writing the data to the textarea.

I have attached my code below:

<%@ page
import="java.sql.*"
import="java.io.*"
import="java.util.*"
import="java.text.SimpleDateFormat"
contentType="text/html;charset=UTF-8"
session="false"
%>
<html>
<head>
<%
/***************** Inserted Parameters **********************/
File transferTemp;
FileInputStream fstream;
DataInputStream in;
DataOutputStream output = null;
String hold = "";
StringBuffer contents;
BufferedReader input = null;
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd
HH:mm:ss");
/*********************************************************** **/
%>
<title>BOM Aggregation Framework Specification Comments</title>
<SCRIPT type="text/javascript">
function writeComments()
{
<%
String value = request.getParameter("NewComments");
String existingVal = request.getParameter("ExistingComments");
%>
alert('test');
alert('<%= value %>');
alert(<%= existingVal %>);
<%

String method = request.getParameter("comment");
/* Cannot enter delimited string in client */
transferTemp = new File("C:\\bass\\files\\log_files\\log_text.txt");

// Open the file that is the first command line parameter
output = new DataOutputStream(new FileOutputStream(transferTemp));

try
{
output.writeBytes("test line" + System.getProperty("line.separator"));

Connection ocon = null;
Class.forName("org.gjt.mm.mysql.Driver");
ocon = DriverManager.getConnection("jdbc:mysql:///bass", "root",
"florida");

Statement stmtt = ocon.createStatement();

stmtt.executeUpdate("Insert into baf_comment(comment) values ('" +
method + "')");

if (ocon !=null) ocon.close();
if (stmtt !=null) stmtt.close();

}
catch (FileNotFoundException ex)
{
ex.printStackTrace();
}
catch (IOException ex)
{
ex.printStackTrace();
}

try
{
if (input!= null)
{
//flush and close both "input" and its underlying FileReader
input.close();
}
}
catch (IOException ex)
{
ex.printStackTrace();
}
%>
}

function readComments(comment)
{
<%

%>
}

</SCRIPT>
<style type="text/css">
body, td, th
</style>

</head>


<body>

<h1 align="center">BOM Aggregation Framework Specification Comments</h1>

<!-- Creates horrizontal bar accross the screen -->
<hr />

<!-- The following section is for inserting new comments -->
<form>
<strong>Comments:</strong><br />
<textarea name="NewComments" id="NewComments" rows="10" cols="100">
Your comments go
here.
</textarea>
<br />
<br />

<%
String value2 = request.getParameter("NewComments");
%>

Text Value: <%= value2 %>


<!-- Submit new comments button -->
<!--
<input type="submit" value="Submit" onclick="alert('Hello from me!');" />
<INPUT TYPE="BUTTON" VALUE="Submit"
onClick="writeComments("NewComments")";">
-->
<%
String value1 = request.getParameter("NewComments");
%>

<INPUT TYPE="BUTTON" VALUE="Submit" onClick="writeComments();" />
<br />
<br />


<!-- Creates horrizontal bar accross the screen -->
<hr />

<!-- The following section is for displaying existing comments -->
<%
/* Test XML file processing */
/* Cannot enter delimited string in client */
transferTemp = new File("C:\\bass\\files\\log_files\\log_text.txt");

// Open the file that is the first command line parameter
fstream = new FileInputStream(transferTemp);

// Convert our input stream to a DataInputStream
in = new DataInputStream(fstream);

// Continue to read lines while there are still some left to read
hold = "";

//...checks on aFile are elided
contents = new StringBuffer();

//declared here only to make visible to finally clause
input = null;

try
{
//use buffering
//this implementation reads one line at a time
input = new BufferedReader( new FileReader(transferTemp) );
String line = null; //not declared within while loop
while (( line = input.readLine()) != null)
{
contents.append(line);
contents.append(System.getProperty("line.separator"));
}
}
catch (FileNotFoundException ex)
{
ex.printStackTrace();
}
catch (IOException ex)
{
ex.printStackTrace();
}

try
{
if (input!= null)
{
//flush and close both "input" and its underlying FileReader
input.close();
}
}
catch (IOException ex)
{
ex.printStackTrace();
}

String commentsData = contents.toString();
%>

<%
String javaOP = "";
Connection ocon = null;
Class.forName("org.gjt.mm.mysql.Driver");
ocon = DriverManager.getConnection("jdbc:mysql:///bass", "root",
"florida");

Statement stmtt = ocon.createStatement();

ResultSet rs = stmtt.executeQuery("Select * from baf_comment");

while(rs.next())
{
javaOP = javaOP + dateFormat.format(rs.getTimestamp(2)) + ": " +
rs.getString(3) + System.getProperty("line.separator");
}

if (rs !=null) rs.close();
if (ocon !=null) ocon.close();
if (stmtt !=null) stmtt.close();
%>

<form action="http://www.htmlref.com/scripts/formecho.php" method="post"
name="form1" id="form1">
<strong>Existing Comments:</strong><br />
<textarea name="ExistingComments" id="ExistingComments" type="text"
rows="10" cols="100">
<%= javaOP %>
</textarea>
</form>
</body>
</html>
Re: JSP textarea [message #168655 is a reply to message #168422] Fri, 05 May 2006 10:08 Go to previous message
Eclipse User
Originally posted by: wknauf_NO_._INSIDE_hg-online.de

Hi Ben !

is your textarea "NewComments" included in a form ? Your jsp code contains only
one <form> element with a textarea "ExistingComments". If it is outside of any
form it is not submitted to the server.

Hope this helps

Wolfgang

Ben Sisson wrote:
> I created a JSP file that would take comments about my web service that
> i created. I am having problems however retrieving the comments from
> the textarea that they are entered into.
>
> I create a textarea that they can enter the comments into:
> <textarea name="NewComments" id="NewComments" rows="10" cols="100">
> Your comments go
> here.
> </textarea>
> <br />
>
>
> <form action="http://www.htmlref.com/scripts/formecho.php" method="post"
> name="form1" id="form1">
> <strong>Existing Comments:</strong><br />
> <textarea name="ExistingComments" id="ExistingComments" type="text"
> rows="10" cols="100">
> <%= javaOP %>
> </textarea>
> </form>
> </body>
> </html>
>
Previous Topic:Exeptions when exporting war file
Next Topic:Generatd Web Service Client
Goto Forum:
  


Current Time: Sat Aug 02 04:37:18 EDT 2014

Powered by FUDForum. Page generated in 0.09295 seconds