File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

JavaScript & JSP Please help

Vit Wipoo

Joined: Feb 27, 2001
Posts: 3
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,
ps: it works fine if i use session.setAttribute("bean", tb) outside JavaScript.
<%@ page session="true" %>
<jsp:useBean id="tb" scope="session" class="testBean" />
<FORM NAME="FORM" ACTION="testBean2.jsp" METHOD="POST" onSubmit="return setSession()">
<script language="JavaScript">
function setSession() {
session.setAttribute("bean", tb);
<BODY>Hey <br>
<jsp:useBean id="tb" scope="session" class="testBean" />
tb = (testBean)session.getAttribute("bean");
<%= tb.getName() %> <br>
<%= tb.getAge() %>
public class testBean {
private String name = null;
private int age = 0;
public testBean() {
public void setName(String 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
I agree. Here's the link:
subject: JavaScript & JSP Please help
It's not a secret anymore!