Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Call a bean from JavaScript 2

Status
Not open for further replies.

otamez

Programmer
Jul 4, 2003
3
MX
How to call a bean from Java Script code when button clicked?

Here is a piece of code on how it is the flow

<script language=&quot;Javascript&quot;>
function validatefields()
{
...Code for validating fields
!!HERE I WANT TO CALL A METHOD FROM MY BEAN!!
}
</script>
<body>
<jsp:useBean id=&quot;UpdateBean&quot; class=&quot;com.class.web.comp.mybean&quot; scope=&quot;session&quot; />
<form name=&quot;myform&quot; >
<input type=&quot;button&quot; name=&quot;SaveProg&quot; value=&quot; Program &quot; onClick=&quot;Javascript:validatefields();&quot;>
</from>
 
Classic web development problem. In a web application that uses server side code you have code the executes in two different locations (1) The Browser (2) The Server

They are not the same even if you are testing with both on the same physical computer.

<jsp:usebean> creates an instance of the Java class in the Servlet executing in the web server context.

<script language=&quot;javascript&quot;> executes in the browser context

The two contexts do not coexist nor for that matter do they even exist at the same point in time as they are synchronous in nature. The only means of communication between the two contexts is to use HTTP REQUEST/RESPONSE data


-pete
 
JSP calls to beans are evaluated at the server, and their values transcribed to HTML at the point where the servlet (all JSP pages are basically evaluated and compiled to servlets byt thekicks out the response to the browser. As palbano says, JSP/Servlets are executed (ie code evaluated) serverside, and JavaScript clientside. The only way to let the two interact is by the medium that is HTML. If you set up in a <FORM> a <INPUT TYPE=&quot;hidden&quot; NAME=&quot;myvalue&quot; VALUE=&quot;whatever&quot;> - this value can be accessed by JSP at server runtime, and also accessed by JavaScript at clientside (document.form[0].myvalue.value) ... hense overcoming your problem of JavaScript interacting with evaluated JSP - simple !!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top