0

I have a logic to generate pdf written in js in my JSP.

AutoDownloadPDF.jsp:

setInterval(function() {
        $.ajax({
        type: "POST",
        url: "GetInvoicesNo.jsp?EntityID=40&MappingID=<%=getMappingID%>",
        async: false,
        success: function(data){    
        var splitData =data.trim().split(',');
                $.each(splitData, function(index, value){
                if(value.trim()!=''){
                var url="GeneratePDF.jsp?EntityCode=<%=getEntityCode%>&InvoiceNo="+value;
        var printWindow = window.open(url,"_blank");
                 }
                        
            });     
                    
    }
    }); 
}, 90000);          

Current Setup:

I'm triggering AutoDownloadPDF.jsp through a Windows batch script like this:

msedge --app=http://localhost:8088/APP/AutoDownloadPDF.jsp 

The process works as intended; however, this method is unsuitable for my server environment because the server may log off, which causes Microsoft Edge to close and interrupts the process.

I tried tools like HTMLUnit and Playwright but didn’t work for me. It seems the problem is that the JSP depends heavily on browser-based JavaScript. Are there any tools or approaches that can handle this effectively?

4
  • Recreate the jsp in javascript and run using node.js - you can use one of these. I am sure they map 1:1 to the jsp code dev.to/xeshan6981/… Commented Jan 1 at 9:30
  • 2
    I'm not really sure what the question is. You've shown JavaScript code, which runs on the client, but not the server-side code that processes the POST request. Please could you show a minimal, reproducible example ( stackoverflow.com/help/minimal-reproducible-example) that demonstrates the problem and explain more clearly what the actual problem is. What do you observe to be happening and what is supposed to happen instead? Commented Jan 1 at 9:42
  • Is there any actual reason you need JS there as opposed to just doing everything server-side/in the Java application? Commented Jan 1 at 14:36
  • @KJ thank you so much for the comment! the Chrome-headless really helpful! it can be generated in the background now! Commented Jan 1 at 18:51

0

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.