Easy help required

Hi All,
I would like an example of a basic jsp page which does the following
Provides a textarea or div for the user to type in some message and when they click submit i want that message to appear
on the page?
can anyone help me with an example?
LVL 25
archrajanAsked:
Who is Participating?
 
bloodredsunCommented:
>>Well also, when i submit again the first one gets erased!

Do you want one that adds it on? Why didn't you say?!

---------------
<html>
<head><title>Form1</title></head>
<body>
<form name="form1" action="form1.jsp">
<textarea name="area"></textarea>
<input type="Submit" value="Submit">
</form>

<%
 String param = request.getParameter("area") != null ? request.getParameter("area") : "" ;
 String sessionParam = (String)session.getAttribute("param") != null ? (String)session.getAttribute("param") : "" ;
 sessionParam += param ;
 session.setAttribute("param" , sessionParam) ;
 out.println(sessionParam) ;
%>

<body>
</html>

-----------
anything else?
0
 
koppchaCommented:
You want it to appear in the same JSP or another JSP
0
 
archrajanAuthor Commented:
Same JSP
Thanks!
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Tomas Helgi JohannssonCommented:
Hi!

Check out this tutorial. You could do it similar to this example.

http://www.jsptut.com/Forms.jsp

Regards,
  Tomas Helgi
0
 
bloodredsunCommented:
form1.jsp
------------------
<html>
<head><title>Form1</title></head>
<body>

<form name="form1" action="form1.jsp">

<textarea name="area"></textarea>

<input type="Submit" value="Submit">
</form>

<%= request.getParameter("area")%>

<body>
</html>
0
 
koppchaCommented:
Myform.jsp
--------------------
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<form action="/Myform.jsp" method="get" name="myForm">
First name:
<input type="text" name="fname" />
<br />
Last name:
<input type="text" name="lname" />
<br />
<input type="submit" value="Submit" />

</form>
First name: <%= request.getParameter("fname") %>
Last name:  <%= request.getParameter("lname") %>


</BODY>
</HTML>
0
 
archrajanAuthor Commented:
bloodredsun,
when i first load the page i get null?

koppcha,
i will try ur solution
0
 
archrajanAuthor Commented:
Well also, when i submit again the first one gets erased!
0
 
bloodredsunCommented:
>>when i first load the page i get null?

yes, as no parameter exists yet


----
new version allowing for null parameter checking
---

<html>
<head><title>Form1</title></head>
<body>

<form name="form1" action="form1.jsp">

<textarea name="area"></textarea>

<input type="Submit" value="Submit">
</form>

<%
 String param = request.getParameter("area") != null ? request.getParameter("area") : "" ;
 out.println(param) ;
 %>

<body>
</html>
0
 
archrajanAuthor Commented:
Thanks,
is there any way i can have the previous messages also on the page?
0
 
bloodredsunCommented:
The above example shows the use of both the request object and the session object in storing and retrieving data. You need to know the difference...
0
 
archrajanAuthor Commented:
Thanks! Thats it!
sorry if i did not ask correctly!
0
 
archrajanAuthor Commented:
well, thanks for the explanation
seems interesting and cool!
0
 
bloodredsunCommented:
No probs archrajan, happy to help :-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.