Step 1: write different web.xml base on different version of the java EE web stack(Servlet/JSP) reference to page
The most important thing is to figure out what version of the Java EE web stack (Servlet/JSP) you are using. There are 2 aspects that factor into this:
- What version of Java EE / servlet spec does your servlet container support?
- What version of Java EE / servlet spec have you declared in your deployment descriptor (web.xml)?
Here’s an example of what to look for in web.xml:
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>web-app-25</display-name> ... </web-app> |
You can see the ‘version=”2.5″‘ designation in here. This means that within this web application, we will be able to use JSP 2.1 and JSTL 1.2 features.
Step 2: download JSTL jar file from http://repo1.maven.org/maven2/javax/servlet/jstl/1.2/ and put it to WEB-INF\lib folder.
Step3: write JSP with JSTL
<%@ page contentType="text/html; charset=utf-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>test asdf jstl</title>
</head>
<body>
<c:out value="hello JSTL"></c:out>
</body>
</html>