posted 25 years ago
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;
}
}