jtsl報錯解決+include標籤 分塊引入前端頁面

繼昨天的code review後,想嘗試前端頁面的include標籤,之前一直是使用jquery.load(),但基於js的加載會存在網絡延遲,若網絡延遲很大,則用戶體驗會非常差。

之前的寫法:

  <script type="text/javascript">
		var a=1;
		if(a==1){		
			$("body").load("../test/toVideoMain");
		}else{
			$("body").load("../user/toLogin");
		}
	</script> 


改進之後的寫法:根據model傳過來的值進行判斷,include哪一個頁面

<c:choose> 
  <c:when test="${from==1}">   
   <%@include file="/WEB-INF/views/VideoMain.jsp" %>
  </c:when> 
  <c:otherwise>   
   <%@include file="/WEB-INF/views/login.jsp" %>
  </c:otherwise> 
</c:choose> 

至此已經成功完成include頁面加載。

附上SSM加入Jstl的配置:

1.pom.xml中增加

<!-- https://mvnrepository.com/artifact/javax.servlet.jsp.jstl/jstl -->
		 <dependency>
			<groupId>javax.servlet.jsp.jstl</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>
	<dependency>
		<groupId>javax.servlet.jsp.jstl</groupId>
		<artifactId>jstl-api</artifactId>
		<version>1.2</version>
		<exclusions>
			<exclusion>
				<groupId>javax.servlet</groupId>
				<artifactId>servlet-api</artifactId>
			</exclusion>
			<exclusion>
				<groupId>javax.servlet.jsp</groupId>
				<artifactId>jsp-api</artifactId>
			</exclusion>
		</exclusions>
	</dependency>

2.將Maven Dependencies下的jstl文件copy到WEB-INF下,並添加至Java Build Path中(最關鍵的一步,今天就是因爲沒做這一步,一直報500錯,一早上都沒有找到原因)

3.頁頭添加

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8" isELIgnored="false"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

就可以使用了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章