title: In a JSP file , how to call a Scriptlet code within a javascript
body: <p>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?</p>
  
  <p>Please give the exact code of how to achieve this</p>
  
  <p>My static scriptlet code is as follows:</p>
  
  <pre><code>    &lt;%@ page language="java" contentType="text/html; charset=ISO-8859-1"
      pageEncoding="ISO-8859-1"%&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"&gt;
  &lt;title&gt;Insert title here&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;%@ page import="java.io.*" %&gt;
  &lt;%@ page import="com.lowagie.text.Document" %&gt;
  &lt;%@ page import="com.lowagie.text.Element" %&gt;
  &lt;%@ page import="com.lowagie.text.html.simpleparser.HTMLWorker" %&gt;
  &lt;%@ page import="com.lowagie.text.html.simpleparser.StyleSheet" %&gt;
  &lt;%@ page import="com.lowagie.text.pdf.PdfWriter" %&gt;
  &lt;%@ page import="com.lowagie.text.pdf.codec.Base64" %&gt;
  &lt;%@ page import="java.util.ArrayList" %&gt;
  &lt;%
      // 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 &lt; 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();
  %&gt;
  Hello!  The time is now
  &lt;%
      // This scriptlet generates HTML output
      out.println( String.valueOf( date ));
  %&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>