alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

jforum example source code file (download_file.jsp)

This example jforum source code file (download_file.jsp) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - jforum tags/keywords

connection, connection, connection_url, exception, exception, into, preparedstatement, runtimeexception, string, string, timestamp, values, version, version

The jforum download_file.jsp source code

<%@page import="java.sql.*, java.util.Date"%>
<%!
static {
	try {
		Class.forName("com.mysql.jdbc.Driver");
	}
	catch (Exception e) {
		throw new RuntimeException(e);
	}
}

private static final String VERSION = "jforum-2.1.8";
private static final String CONNECTION_URL = "jdbc:mysql://localhost/jforum?user=root&password=root";
%>
<%
String type = request.getParameter("type");
String file = null;

if ("zip".equals(type)) {
	file = VERSION + ".zip";
}
else if ("war".equals(type)) {
	file = VERSION + ".war";
}
else if ("src".equals(type)) {
	file = VERSION + "-src.zip";
}

if (file == null) {
	out.println("<h3>Cannot file the requested file");
}
else {
	Connection conn = null;
	PreparedStatement p = null;
	
	try {
		conn = DriverManager.getConnection(CONNECTION_URL);
		p = conn.prepareStatement("INSERT INTO releases_download (file, downloadDate) VALUES (?, ?)");
		p.setString(1, file);
		p.setTimestamp(2, new Timestamp(new Date().getTime()));
		p.executeUpdate();
	}
	finally {
		if (p != null) {
			try { p.close(); } catch (Exception e) {}
		}
		
		if (conn != null) {
			try { conn.close(); } catch (Exception e) {}
		}
	}
	
	response.sendRedirect("releases/" + file);
}
%>

Other jforum examples (source code examples)

Here is a short list of links related to this jforum download_file.jsp source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.