1

I have the above js and JSP code, I want to invoke procedureCall() while clicking on ok button on confirm window poopup (inside "if" statement). Is it possible and if yes, how it can be done?

<script type="text/javascript">
        function confirmDelete() {
            var answer = confirm("Are you sure you want to delete");
            if (answer == true) {
                return true;
            } else {
                return false;
            }
        }
</script>

JSP piece:

<%!    public void procedureCall(int cId) {
            String procedureCall = "{call NEW_PORTING_PRC.delete_album_metadata(cId)}";
                try (CallableStatement cal = conn.prepareCall(procedureCall);) {

                } catch (Exception e) {
                    e.printStackTrace();
                }
%>

2 Answers 2

2

javascript runs in your browser, your java code is deployed in your container(Tomcat). So only way to invoke this is via a Web call. Your javascript should invoke an ajax call to one servlet(configured in web.xml) and this servlet should invoke your java method. like from JS you write as

 $.get('URLofServlet');

OR what you can try is submit the JSp with some parameters and reloading the JSP..

if (answer == true) 
{
   document.getElementById("param1").value='paramvalue';
   document.getElementById("myForm").action='yourJspPath.jsp';
   document.getElementById("myForm").submit();
}

Also I assume id and name will both be 'param1' for simplicity.. and in scriptlet you can do like

<%
    if(request.getParamter("param1")=='paramvalue'){procedureCall();}
%>

Just to add I will recommend to remove scriplets and use ajax as in first approach.

Sign up to request clarification or add additional context in comments.

Comments

0

Use form submission or ajax request or framework action to go back end and process the things needed for you.In your approach its not possible I think. And please dont use scriplets in jsp,its not a good practice.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.