File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes URGENT- - - - Related to Session in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "URGENT- - - - Related to Session in JSP" Watch "URGENT- - - - Related to Session in JSP" New topic
Author

URGENT- - - - Related to Session in JSP

sanjay mahajan
Greenhorn

Joined: May 07, 2001
Posts: 5
--------------------------------------------------------------------------------
I have two jsp pages as follows.....
-----------------------------------------------------------------
(Purpose of this JSP page is to allow a user to type a birthday message in a textarea .This message written then would be posted to the second JSP which is like a bulletin board )
Message.jsp
<%@ page language="java" %>
<html>
<head>
<script language= "javascript">
function check(){
if( (formW2.birth_wishes.value=="")){
alert("Please write a Birthday Message.")
document.formW2.birth_wishes.focus()
}
else {
if( confirm("Do you wish to send message")) {
document.formW2.submit();
}
else {
document.formW2.birth_wishes.focus()
}
}
}
</script>
</head>
<body onload="document.formW2.birth_wishes.focus();">
<FORM Name="formW2" METHOD=POST ACTION="noname1newer.jsp">
<table>
<tr>
<td valign=middle align=middle height=20%>
<TEXTAREA NAME="birth_wishes" ROWS="3" COLS="92"></TEXTAREA>
</td>
</tr>

<tr><td valign=middle align=middle height=10>
<INPUT TYPE="button" NAME="SUBMIT" VALUE= "SEND_MESSAGE"
onClick="check()">
<INPUT TYPE="reset" NAME="RESET" VALUE = "CLEAR MESSAGE"
OnClick="document.formW2.birth_wishes.focus();">
</td> </tr>
</form>
</table>
</body>
</html
-------------------------------
Second JSP page..
(Purpose to fetch the message send by user and display it..)
Display.jsp
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<html>
<head>
<%! String send_name; %>
<%! String send_message; %>
</head>
<body bgcolor="#BBDSFB">
<% send_message = request.getParameter("birth_wishes");
session.putValue( "birth_wishes", send_message ); %>
<TABLE>
<tr>
<td valign=top>
<FONT SIZE="4" COLOR="black" face="Arial">
<%= send_message %>
</FONT>
</td>
</tr>
</TABLE>
</body>
</html>
-----------------------------------------------------------------
This two pages are functioning absolutely ok..
ie the message written in Message.jsp is posted to Display.Jsp
and it displays the message.
But What i actually intend to do is
when the first message send and then displayed,
after that someone else goes to Message.jsp and if he post the message,the new(this message)and previous message both should be displayed.
Similarly the next user posting the mesage should be able to see their and the previously posted message..
How to got about it??
k b
Greenhorn

Joined: Feb 01, 2001
Posts: 22
Can you use DataBase Table ? If so ,you can show the user any previous message he has posted not only for this session, but including old ones. If you donot want to use table then you can keep in Session using session.setAttribute() and retrieve them using getAttribute(). For this you have to maintain a session level counter and while putting the attribute use the counter as an suffix to the name.
session.setAttribute("name" + counter, message);
While getting the attribute loop for counter times and get it.
Hope this helps
khudi
Maky Chopra
Ranch Hand

Joined: Apr 11, 2001
Posts: 149
k b,
The javaranch has a naming policy and your login name does not meet the requirement.
Please signup again with a proper name.
Thanks..
sanjay mahajan
Greenhorn

Joined: May 07, 2001
Posts: 5
I have given the proper name of mine.
sanjay mahajan is my name.
and as specified there is a space between my firstname (sanjay) and the last name(mahajan).
so what is that you are finding is wrong.
I have read your naming policy and It seems I have full filled all the norms.
Still if you feel I have overlooked it please do specify.
Thanks.

Originally posted by Mak Bhandari:
k b,
The javaranch has a naming policy and your login name does not meet the requirement.
Please signup again with a proper name.
Thanks..

Maky Chopra
Ranch Hand

Joined: Apr 11, 2001
Posts: 149
hi sanjay,
you overlooked something That message is for k b
sanjay mahajan
Greenhorn

Joined: May 07, 2001
Posts: 5
mak,
Yes i did overlooked it was for k b.
i must have overlooked as it came to query i have posted.
Anyway thanks for getting that to my notice.
Now do me one more favour .If possible please try to solve rather guide me to solve the problem i have posted.

Maky Chopra
Ranch Hand

Joined: Apr 11, 2001
Posts: 149
The way I understand your problem, you want to accept information from page1.jsp and then display that 'greetings' in page2.jsp
What are your requirements ? Obviously, you need something static that wont go away when sessions expire which any visitor to your site can see. In that case, sessions cant help you as page2.jsp will show only the person who entered the greeting that greetings. Sessions are user specific.. If the person closes the browser and comes again, the data will be lost...
You need a permanent data storage to hold the greetings.. A database would best handle your requirement.
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Sanjay,
I have this thought. You can have a 'application'/'ServletContext' scoped variable set.
servletContext.setAttribute("greetVector",vectorRef);
Add all your user's greetings to this vecRef Vector. You can make this portion (reading/writing to vector) alone synchronized . Often you write the vector to disk (file)/database.
Here is a sample maintenance servlet code which I checked and found good.
http://www.coolservlets.com/Maintenance/
regds
maha anna

[This message has been edited by maha anna (edited May 08, 2001).]
sanjay mahajan
Greenhorn

Joined: May 07, 2001
Posts: 5
Mahha Anna,
Thanks.
for the guidance.
Yes I too am thinking on that line itself.

Mak Bhandari & k b,
Their two reasons that I didnt wanted to to use tables are
firstly ...
I would wish to display the message send for& during a single day only.And not store them permanently.Because they wont be needed in future.
The messages are just Birthday Wishes those would be send by any employee to an individual on his birthday.So need to persist for
that day itself.
secondly...
Being new to JSP i thought this using Session with application as scope would be easier than to storing in database and retriving them to display.
David O'Meara(Dave)
You were the first person to respond to my query.
It really brought a smile on face to see a response to my query.

From all the above feedbacks we could converge on following thing..
there two ways for a solution to my query
1)Use Session with application scope & use vector to store the message ...
2)else use database to store and retrieve database..

Both these solution really seem to be appropriate..
So atleast I am clear in what way I have to approach my query.
Thanks to all.
To all of you I will like to tell you.I am happy to be part of this forum because its so active forum.
Also I have registered in other JSP forums but they are not so alive as this forum of ours is.
KEEP IT UP.

 
wood burning stoves
 
subject: URGENT- - - - Related to Session in JSP