jsp and javascript communication
function dropdown
{
if(x==1)
{
<%String unit="apple;%>
}
else if(x==1)
{
<开发者_如何转开发;%String unit="orange";%>
}
connection to db.......
}
is my code.......only the last loop gets executed.... based on unit...i need to connect to database.....can any one guide me
- The browser makes a request
- The webserver runs the JSP
- The webserver delivers an HTTP resource to the browser
- The browser parses the HTML and executes any JS in it
JavaScript control statements (like if
and else
) won't stop JSP code from executing (JS is
and else
just mean "Print this text to the browser" as far as JSP is concerned). At this stage, it is too late to send data to the JSP program as it has finished executing.
You need to make a new HTTP request to get data back to it.
You probably want to use Ajax for this, but do build on things that work (i.e. have a normal form submission). jQuery provides a convenient abstraction layer.
精彩评论