JavaScript tags in HTML document throws a parsing error
PHP Fatal error: Uncaught Spipu\Html2Pdf\Exception\HtmlParsingException: The HTML tag provided is invalid in /vendor/spipu/html2pdf/src/Parsing/TagParser.php:44
Fixes: For HTML2PDF < 5.x (html2pdf.class.php)
/**
* tag : script
* mode : OPEN
*
* @param array $param
* @return boolean
*/
protected function _tag_open_Script($param)
{
return $this->_tag_open_B($param, 'script');
}
/**
* tag : script
* mode : CLOSE
*
* @param array $param
* @return boolean
*/
protected function _tag_close_script($param)
{
return $this->_tag_close_B($param);
}
Difference between Java Servlet and JSP
Servlet is html in java whereas JSP is java in html. Servlets run faster compared to JSP. … JSP is a webpage scripting language that can generate dynamic content while Servlets are Java programs that are already compiled which also creates dynamic web content. In MVC, jsp acts as a view and servlet acts as a controller.
Servlet example: Hello.java
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
writer.println("<html>");
writer.println("<head>");
writer.println("<title>This is my .java file to .class file. Sample Application Servlet Page</title>");
writer.println("</head>");
writer.println("<body bgcolor=white>");
writer.println("<table border=\"0\">");
writer.println("<tr>");
writer.println("<td>");
writer.println("<img src=\"images/tomcat.gif\">");
writer.println("</td>");
writer.println("<td>");
writer.println("<h1>Sample Application Servlet</h1>");
writer.println("This is the output of a servlet that is part of");
writer.println("the Hello, World application.");
writer.println("</td>");
writer.println("</tr>");
writer.println("</table>");
JSP example: hello.jsp
<table border="0">
<tr>
<td align=center>
<img src="images/tomcat.gif">
</td>
<td>
<h1><%= new String("Sample Application JSP Page") %></h1>
This is the output of a JSP page that is part of the Hello, World
application.
</td>
</tr>
</table>
Convert .class to .java
cd to the folder that contains .class file, type the command below (without .class extension). The class will be de-compiled to java code
C:\Path-to-Class-File\classes\mypackage>javap -c Hello
You’ll see the code of .java file that look like this in the terminal.
Compiled from "Hello.java"
public final class mypackage.Hello extends javax.servlet.http.HttpServlet{
public mypackage.Hello();
Code:
0: aload_0
1: invokespecial #1; //Method javax/servlet/http/HttpServlet."<init>":()V
4: return
public void doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.Http
ServletResponse) throws java.io.IOException, javax.servlet.ServletException;
...
How to write an Object to a file
Java object can be written into a file for future reference. This process is called Serialization (translating data structures or object state into a format that can be store). In order to do that, we have to implement the Serializable interface, and use ObjectOutputStream to write object into a file.
FileOutputStream fout = new FileOutputStream("c:\\temp\\address.txt");
ObjectOutputStream oos = new ObjectOutputStream(fout);
oos.writeObject(address);
Adding JUnit and Hamcrest for Testing in Java
package test.string;
import java.lang.String;
import static org.junit.Assert.assertThat;
import org.junit.Test;
public class StringFormatTestCase {
@Test
public void testNumberFormattingWithLeadingZeros() {
final String formatted = String.format("%04d", 1);
assertThat(formatted, equalTo("0001"));
}
@Test
public void testDoubleFormattingWithTwoDecimalPoints() {
final String formatted = String.format("%.2f", 12.324234d);
assertThat(formatted, equalTo("12.32"));
}
}
Errors
Error:(3, 33) java: package org.junit does not exist
Error:(3, 2) java: static import only from classes and interfaces
Error:(5, 25) java: package org.junit does not exist
Error:(6, 12) java: package org.junit does not exist
Error:(12, 10) java: cannot find symbol
symbol: class Before
location: class edu.kit.ipd.swt1.StringFormatTestCase
Error:(17, 11) java: cannot find symbol
[...]
In order to fix it we had to Open Module Settings for that project and manually add jar Dependencies junit-4.12.jar and hamcrest-core-1.3.jar which are contained in the IntelliJ installation lib directory (C://Program Files/JetBrains/lib/xxx.