Win a copy of Java Mock Exams (software) this week in the Programmer Certification (OCPJP) forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Session Attributes

 
Ramesh Sunkara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
###create_slice.jsp###

<%@page import="java.lang.*" %>
<%
HttpSession slicesession = request.getSession();
String ipValue2=(String)slicesession.getAttribute("ip");
%>

<html>
<head>
<title>SLICE_NAME</title>

<script language=javascript type="text/javascript">
function openUrl()
{
var file1="http://";
var file2="<%= ipValue2%>";
var file3=":46000/cgi-bin/sliver.cgi?command=SLICE&SLICENAME="
var file=file1+file2+file3;
parent.demo_content.location=file;
}


function submitenter(e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
{
openUrl();
return false;
}
else
return true;
}

</script>


</head>
<body>
<form class="c1" name="url" target="_blank" id="url" >
SLICENAME:
<input type="text" id="slicename" name="slicename" size=20 onKeyPress="return submitenter(event)"></input>
<input type="submit" id="txtInput" value="Ok" onClick="" ></input>
</form>

</body>
</html>


My problem is

1) I have to display <slice name> value in another jsp.

2) There is no communication between these two jsp's through RequestedDispatcher or.. sendRedirect or.. atleast through action.

3) So the only means I found to achieve is using setAttribute("slicename",<slicevalue>);

4) But i cannot get the slice value. Because the jsp code is executing even before am entering the value in textfield. So am getting null value when i use

String s=(String)request.getParameter('slicename")
<session-name>.setAttribute("slicename",s);

Here the value being set is null.


Can anyone please help me.

PROBLEM IS AM UNABLE TO GET THE VALUE OF A TEXTFIELD IN THE SAME JSP TO SET IT.

 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should set the variable in Session (in your action class/servlet), when the form is submitted.

I think, you should first understand where/when the java code in JSP is executed.
 
Ramesh Sunkara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Chinna

can you please tell me the solution for it now. I cannot use another servlet here in action since the create_slice.jsp should retain in the frame.

Thank You.
 
Chinna Eranna
Ranch Hand
Posts: 174
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once the user press submit in this page.. where does the request goes ?

I mean.. what is the jsp/action class that is invoked ?
 
Pushkar Choudhary
Rancher
Posts: 425
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ramesh,
Please use code tags while posting any code, since code without tags is very difficult to read.
 
Ramesh Sunkara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First thing here there is no submit button..

once we click ok button which is in th page. some url will be genereated dynamically(for which i wrote script) and opened in other frame
 
Ramesh Sunkara
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
###create_slice.jsp###


[code]

<%@page import="java.lang.*" %>
<%
HttpSession slicesession = request.getSession();
String ipValue2=(String)slicesession.getAttribute("ip");
%>
[code]

<html>
<head>
<title>SLICE_NAME</title>

<script language=javascript type="text/javascript">
function openUrl()
{
var file1="http://";
var file2="<%= ipValue2%>";
var file3=":46000/cgi-bin/sliver.cgi?command=SLICE&SLICENAME="
var file=file1+file2+file3;
parent.demo_content.location=file;
}


function submitenter(e)
{
var keycode;
if (window.event) keycode = window.event.keyCode;
else if (e) keycode = e.which;
else return true;

if (keycode == 13)
{
openUrl();
return false;
}
else
return true;
}

</script>


</head>
<body>
<form class="c1" name="url" target="_blank" id="url" >
[code]
SLICENAME:
<input type="text" id="slicename" name="slicename" size=20 onKeyPress="return submitenter(event)"></input>
[code]
<input type="button" id="txtInput" value="Ok" onClick="" ></input>
</form>

</body>
</html>


My problem is

1) I have to display <slice name> value in another jsp.

2) There is no communication between these two jsp's through RequestedDispatcher or.. sendRedirect or.. atleast through action.

3) So the only means I found to achieve is using setAttribute("slicename",<slicevalue>);

4) But i cannot get the slice value. Because the jsp code is executing even before am entering the value in textfield. So am getting null value when i use

String s=(String)request.getParameter('slicename")
<session-name>.setAttribute("slicename",s);

Here the value being set is null.


Can anyone please help me.

PROBLEM IS AM UNABLE TO GET THE VALUE OF A TEXTFIELD IN THE SAME JSP TO SET IT.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you see your post once you make it? Please notice that it's still not formatted.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Besides that you're trying to do stuff in a JSP that should be done in Java, you have a fundamental misunderstanding. If you're submitting to a JSP, it's in *that* JSP that you'd need to set a session value.
 
Happiness is not a goal ... it's a by-product of a life well lived - Eleanor Roosevelt. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!