0

I am working on Java Web Application which actually is a coding competition platform. Focussing upon only two modules, code.jsp and Compile.java. In JSP, there is a button(compile/submit) and an option pane (for language selection e.g. C or C++). Now I am creating an object of Compile Class and i have to pass language chosen from option pane and button choosen as its method's parameter. So how can i get values of both elements and pass them to java method.

This is for Windows server, and I am using Apache 8.5 with Oracle 12c as database

function compile()
    {
        var sel=document.getElementById("slct");
        var lang=sel.options[sel.selectedIndex].text;
        var cd=document.getElementById("cd");
        var code=cd.value;
        var button=document.getElementByName("sbt");
        var btn=button.value;
        <%
            Compile c=new Compile(questag,pool,lang,clg,code,btn);
            b=c.compi();
            System.out.println(b.getExpOut());
        %>
    }

Expected is : those variables lang,code,btn can be passed in the java method. Error is : they are JS variables and cant be passed like this.

Spatz
  • 18,640
  • 7
  • 62
  • 66
  • The key is to realize, **where** and **when** which code is executed - JSP on the server, when the page is requested and rendered (i.e. **before** the response is sent to the browser), and Javascript in the browser, **after** the browser receives the **already generated** response. – Jozef Chocholacek Aug 09 '19 at 11:56
  • As you write, _they are JS variables and cant be passed like this_ - i.e. you have to find a method to pass them to the back-end (server), and get back the response. I suggest you start here: https://stackoverflow.com/questions/4112686/how-to-use-servlets-and-ajax – Jozef Chocholacek Aug 09 '19 at 11:58

0 Answers0