wood burning stoves 2.0*
The moose likes Servlets and the fly likes JavaScript & JSP  Please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "JavaScript & JSP  Please help" Watch "JavaScript & JSP  Please help" New topic
Author

JavaScript & JSP Please help

Vit Wipoo
Greenhorn

Joined: Feb 27, 2001
Posts: 3
Hi,
i'm very new to JSP. i'm doing a page that shows names of members and some information. i want to have one button for each member that allow users to see more information in another page when they click. i have an array of memberBean and i'm trying to set a specific bean(the one that is clicked) for session by "session.setAttribute("bean", memberBean);" to pass bean to another page. i know it looks easy but i really can't do that. codes below are my test case. please suggest me what to do or alternative ways to do this.
thanks a lot,
Vit
ps: it works fine if i use session.setAttribute("bean", tb) outside JavaScript.
[testBean1.jsp]
<%@ page session="true" %>
<HTML>
<BODY>
<jsp:useBean id="tb" scope="session" class="testBean" />
<%
tb.setName("Chanvit");
tb.setAge(25);
%>
<FORM NAME="FORM" ACTION="testBean2.jsp" METHOD="POST" onSubmit="return setSession()">
<INPUT TYPE="SUBMIT" VALUE="Click">
</FORM>
<script language="JavaScript">
<!--
function setSession() {
session.setAttribute("bean", tb);
}
//-->
</script>
</BODY>
</HTML>
[testBean2.jsp]
<HTML>
<BODY>Hey <br>
<jsp:useBean id="tb" scope="session" class="testBean" />
<%
tb = (testBean)session.getAttribute("bean");
%>
<%= tb.getName() %> <br>
<%= tb.getAge() %>
</BODY>
</HTML>
[testBean.java]
public class testBean {
private String name = null;
private int age = 0;
public testBean() {
}
public void setName(String name){
this.name = name;
}
public String getName() {
return name;
}
public void setAge(int age) {
this.age = age;
}
public int getAge() {
return age;
}
}
Chris Stehno
Ranch Hand

Joined: Feb 26, 2001
Posts: 180
It looks like one of your problems is that you are trying to access the session object from JavaScript. The session object does not carry over into the JavaScript world and it is only available inside the Java code of the JSP page.
Hope this helps


- Chris Stehno, SCPJ
 
Consider Paul's rocket mass heater.
 
subject: JavaScript & JSP Please help