1. 程式人生 > >如何才能在jsp檔案中使用el表示式

如何才能在jsp檔案中使用el表示式

jsp引入el表示式

1、需要的jar包

jstl.jar
standard.jar

2、建立一個jsp檔案如下

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"
; %>
<!-- 引入el標識所需要的標籤 --> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Welcome</title> <style type="text/css"> a
{ text-decoration: none }
</style> </head> <body> <!-- 在這裡便可以使用el表示式了 --> <h1>網站的主頁面${sessionScope.currentUser.userName }</h1> <a href="<%=basePath %>success.action">個人主人</a> <a href="<%=basePath %>login.action"
>
個人主人</a> </body> </html>

3、最後宣告

我建立的是web專案,使用的是tomcat7.0。不引入jstl標籤隔閡standard.jar無法使用。同時別忘記在jsp中引入標籤。