0

I have a static scriptlet code which works fine. I want to call this static code when the user clicks on a button in the html page. So is it possible to create a function in javascript, which is called when the user clicks the html button and inside the function the scriptlet code be placed?

Please give the exact code of how to achieve this

My static scriptlet code is as follows:

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%@ page import="java.io.*" %>
<%@ page import="com.lowagie.text.Document" %>
<%@ page import="com.lowagie.text.Element" %>
<%@ page import="com.lowagie.text.html.simpleparser.HTMLWorker" %>
<%@ page import="com.lowagie.text.html.simpleparser.StyleSheet" %>
<%@ page import="com.lowagie.text.pdf.PdfWriter" %>
<%@ page import="com.lowagie.text.pdf.codec.Base64" %>
<%@ page import="java.util.ArrayList" %>
<%
    // This scriptlet declares and initializes "date"
    Document pdfDocument = new Document();
        Reader htmlreader = new BufferedReader(new InputStreamReader(
                                 new FileInputStream("E:\\test.html")
                                ));


        htmlreader.read();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        PdfWriter.getInstance(pdfDocument, baos);
        pdfDocument.open();

        StyleSheet styles = new StyleSheet();
        styles.loadTagStyle("body", "font", "Bitstream Vera Sans");
        ArrayList arrayElementList = HTMLWorker.parseToList(htmlreader, styles);
        for (int i = 0; i < arrayElementList.size(); ++i) {
            Element e = (Element) arrayElementList.get(i);
            pdfDocument.add(e);
        }
        pdfDocument.close();



        byte[] bs = baos.toByteArray();
        String pdfBase64 = Base64.encodeBytes(bs); //output
        File pdfFile = new File("E:\\test.pdf");
        FileOutputStream output = new FileOutputStream(pdfFile);
        output.write(bs);
        output.close();
    System.out.println( "Evaluating date now" );
    java.util.Date date = new java.util.Date();
%>
Hello!  The time is now
<%
    // This scriptlet generates HTML output
    out.println( String.valueOf( date ));
%>
</body>
</html>

1 Answer 1

1
is it possible to create a function in javascript which is called when the 
user clicks the html button

Answer: Yes

and inside the function the scriptlet code be placed?

Answer: No

The solution is to make use of Javascript ajax. If you are using jquery make use of jquery ajax.

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

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.