By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,537 Members | 1,471 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,537 IT Pros & Developers. It's quick & easy.

Accessing a jsp:usebean from javascript...?

P: n/a
My code is like that :

<jsp:useBean id="vConf" type="cat.eur.tb.eleccard.datatypes.Config[]"
scope="session" />
<jsp:useBean id="equNo" type="java.lang.Integer" scope="session" />

<script language="javascript">
function submit_form()
{
var equ = vConf[equNo].getEqu();
(...)
}

The problem is that both vConf and equNo are not known. I tried with
<%=...%>
and it is still inaccessible.

It is correct ? can I do it ? Where I am wrong ?
Jul 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
In article <66**************************@posting.google.com >,
br*************@yahoo.fr enlightened us with...
My code is like that :

<jsp:useBean id="vConf" type="cat.eur.tb.eleccard.datatypes.Config[]"
scope="session" />
<jsp:useBean id="equNo" type="java.lang.Integer" scope="session" />

The bean is interpreted by the server (servlet engine). The browser sees
no such thing. View the HTML source to see what the browser sees.
Javascript, as you are using it, runs on the client, well after the
server is done. It cannot call bean methods.
<script language="javascript">
function submit_form()
{
var equ = vConf[equNo].getEqu();


If you want the value of that method in a js variable, assign it at run
time.
var equ = <%= vConf[equNo].getEqu() %>;
If the above method returns a string, put it in quotes.
var equ = "<%= vConf[equNo].getEqu%>";

The above assumes both beans are written properly and their methods
return what is expected. If you aren't sure, ask in
comp.lang.java.programmer

--
--
~kaeli~
To steal ideas from one person is plagiarism; to steal from
many is research.
http://www.ipwebdesign.net/wildAtHeart
http://www.ipwebdesign.net/kaelisSpace

Jul 20 '05 #2

P: n/a
Brice Laurencin wrote:
<jsp:useBean id="vConf" type="cat.eur.tb.eleccard.datatypes.Config[]"
scope="session" />
<jsp:useBean id="equNo" type="java.lang.Integer" scope="session" />

<script language="javascript">
The "language" attribute is deprecated since
HTML 4, but the "type" attribute is required:

<script type="text/javascript">
function submit_form()
{
var equ = vConf[equNo].getEqu();
(...)
}
[...]

It is correct ?
No.
can I do it ?
Possibly.
Where I am wrong ?


You are using client-side JavaScript here. Client-side code cannot
access server-side code (directly). JavaServer Pages generates content
temporarily in the server's memory by replacing markup in the file
(check out "view-source:") and sends that composed data to the client
which interprets it. You can only access the *replaced* content with
client-side scripting through the DOM of the UA, unless the server-side
application provides an API for server-side JavaScript.
PointedEars
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.