Showing posts with label Tomcat. Show all posts
Showing posts with label Tomcat. Show all posts

Tuesday, December 11, 2012

How to enable manager app for Tomcat with Virtual Host

Make a copy of the file
       ${tomcat-home}/webapps/host-manager/manager.xml

and copy to the folder (the same name with your virtual host folder under webapps)
       ${tomcat-home}/conf/Catalina/<your virtual host folder name>

Access via browser with the link http://<your virtual host name>/manager/html



Saturday, January 28, 2012

How to embed fonts into PDF generated by JasperReport (iReport)

Setup:
» Tomcat 7.0 + JSP
» iReport 4.1.1

Reference:
http://javaskeleton.blogspot.com/2010/12/embedding-fonts-into-pdf-generated-by.html

Steps:
1. Launch iReport, choose Tools->Options->Fonts

2. Click "Install Font" and follow the wizard to install your desired font.



*Remember to tick the option "Embed this font in the PDF document"








3. Select the newly installed font and click the button "Export as extension"




4. Save the export file as JAR file

5. Copy the JAR file to the folder within your application classpath
*I choose to put all the JAR files into $(JRE_HOME}/lib/ext

Friday, January 13, 2012

How to display/Store Chinese Character Thru Browser

The following is extracted from http://java.sun.com/developer/technicalArticles/Intl/HTTPCharset/#browser

Server: Tomcat
1. Setting the context parameter is done in the WEB-INF/web.xml file.

<context-param>
<param-name>PARAMETER_ENCODING</param-name>
<param-value>UTF-8</param-value>
</context-param>

2. Add the following code to your JSP file.
<%
    //Must put in the first section of the jsp page
    String paramEncoding = application.getInitParameter("PARAMETER_ENCODING");
    request.setCharacterEncoding(paramEncoding); 

%>
*Please note that the following lines must be inserted at the begining of the JSP page after header declaration (eg. tagLib or Page), before any other content processing.

Friday, January 6, 2012

Run JasperReport (ireport) in JSP

(1) Import the following libraries to your project
===================================================
jasperreports-3.7.2.jar
iText-2.1.7.jar
jdt-compiler-3.1.1.jar
groovy-all-1.5.5.jar
commons-logging-api-1.1.jar
commons-logging-adapters-1.1.jar
commons-logging-1.1.jar
commons-digester-1.8.jar
commons-collections-testframework-3.2.jar
commons-collections-3.2.jar
commons-beanutils-core.jar
commons-beanutils-bean-collections.jar
commons-beanutils.jar

(2) Sample JSP Code
===================================================
String dirPath = "ireports";
String realPath = this.getServletContext().getRealPath(dirPath);
String orderNo = request.getParameter("orderNo");
String jasperReport = "nameCardFront.jasper";
JasperPrint print = null;
String outputFileName = null;
Connection conn = null;

try{
InitialContext initialContext = new InitialContext();
DataSource ds = (DataSource)initialContext.lookup("java:comp/env/jdbc/DOS");
conn = ds.getConnection();

Map parameters = new HashMap();
parameters.put("orderNo", "a");
print = JasperFillManager.fillReport(realPath + "//" + jasperReport, parameters, conn);

SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd-HHmmss");
outputFileName = "file.pdf";

out.clearBuffer();
//set the content type(can be excel/word/powerpoint etc..)
response.setContentType ("application/pdf");
//set the header and also the Name by which user will be prompted to save
response.setHeader ("Content-Disposition", "attachment; filename=\"" + outputFileName);

JasperExportManager.exportReportToPdfStream(print, response.getOutputStream());

}
catch(Exception ex){
ex.printStackTrace();
out.println(ex.getMessage());
}
finally{
if (conn != null)
conn.close();
}

Monday, August 16, 2010

Netbeans 6.8 with Tomcat 6.0.20 - Requires JDK 6 Update 20

Netbeans 6.8 + Tomcat 6.0.20

Tested worked with JDK 6 Update 20

JDK 6 Update 19, JDK 6 Update 21 failed to work

Error:
In any jsp file, Netbeans will highligh error for the following lines

<%@ page contentType="text/html" session="true" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

*Courtesy of Andy Lim*

Thursday, February 4, 2010

Deploy Netbeans 6.1 Web Application to Tomcat 5.5

Netbeans 6.1 come bundles with Tomcat 6.0. So you will encounter problem if you upload the war file directly to your production Tomcat 5.5 server.

Reason being the web.xml in you war file use version 2.5 XML declaration but Tomcat 5.5 uses version 2.4. The web.xml is located at
<catalina-home>/webapps/<your apps>/WEB_INF

Look at the first two lines of the web.xml, you shall see something like the following

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">


Whereas in Tomcat 5.5, the two lines shall be replaced with the following

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

After which, you have to clear the cache of compiled JSP file.
<catalina-home>\work\Catalina\<your apps>

Remove the whole folder with name "_" (underscore). This is the compiled JSP file (java class) by tomcat and is compiled only once when the jsp page is accessed/requested for the first time.

You have to stop the tomcat before removing the folder.
The folder will be rebuild automatically after you have restarted the tomcat and the jsp is being accessed.