Get JSTL to run on Tomcat in Eclipse

Get JSTL to run on Tomcat in Eclipse

This tutorial shows how to get JSTL to run on Eclipse in two steps.

1. Import tag libraries

Place the following tag libraries before the <!DOCTYPE html> declaration.


<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/sql" prefix="sql"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>

2. Download the right jar file

Download the latest jstl.jar from https://jstl.java.net/ and drop it in your WEB-INF/lib directory.

Now you’re all set to start using JSTL in your JSPs!

Establish Database connection in JSTL

If you need to establish a database connection using JSTL, you will need to download the latest mysql-connector.jar from http://dev.mysql.com/downloads/connector/j/ and drop it in your WEB-INF/lib directory.

Then place the code below in your <head></head> tag. Change the value of ‘yourdatabase’, ‘yourusername’ and ‘yourpassword’ to your databases actual name, username and password.


<sql:setDataSource var="snapshot" driver="com.mysql.jdbc.Driver" 
url="jdbc:mysql://localhost:8080/yourdatabase" user="yourusername"  password="yourpassword"/> 

You should now be able to connect to your database.

Seda
Seda Kunda is a web designer and developer with a degree in Computer Science and a great passion for code. Besides code, she enjoys pepperoni pizza, watching the bachelor and sleeping in on Saturdays.
Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

One thought on “Get JSTL to run on Tomcat in Eclipse

Comments are closed.