开发者

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


  1. The browser makes a request
  2. The webserver runs the JSP
  3. The webserver delivers an HTTP resource to the browser
  4. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜