struts2學習筆記①

在學習Struts2的include標籤中出現了問題
html

  環境:win8.1+Eclipse IDE for Java EE Developers (4.3.2)+Tomcat7.0.52java

      使用Struts2 jar包以下:apache

          

  有s-include.jsp頁面以下:tomcat

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>使用s:include標籤來包含目標頁面</title>
</head>
<body>
    <h2>使用s:include標籤來包含目標頁面</h2>
    <!-- 使用include標籤來包含其餘頁面 -->
    <s:include value="included-file.jsp"/>
    <!-- 使用include標籤來包含其餘頁面,而且傳入參數 -->
    <s:include value="included-file.jsp">
        <s:param name="author" value="'issa'"/>
    </s:include>    
</body>
</html>

 

  included-file.jsp頁面以下:服務器

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>被包含的頁面</title>
</head>
<body>
    <h3>被包含的頁面</h3>
    author參數值爲:${param.author}
</body>
</html>

  運行s-include.jsp頁面,結果eclipse

          

  獲得源碼爲:jsp

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>使用s:include標籤來包含目標頁面</title>
</head>
<body>
    <h2>使用s:include標籤來包含目標頁面</h2>
    <!-- 使用include標籤來包含其餘頁面 -->
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>
    <!-- 使用include標籤來包含其餘頁面,而且傳入參數 -->
    
        
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>    
</body>
</html>

  控制檯有信息:學習

      At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.this

  解決方法:編碼

    ①. 註釋<!--  -->

    ②. 將included-file.jsp頁面改成

<h3>被包含的頁面</h3>
    author參數值爲:${param['author']}

    ③. 修改tomcat屬性,忽略對EL表達式的關鍵字檢查。修改$CATALINA_BASE/conf/catalina.properties文件,添加org.apache.el.parser.SKIP_IDENTIFIER_CHECK=true選項

    選項①、②後仍有如上信息,選項③後消除。但s-include.jsp頁面運行結果仍然空白!

  控制另有警告:

      警告: [SetContextPropertiesRule]{Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Struts2Tag' did not find a matching property.

  解決方法:(無效

    1.關閉服務器

    2.雙擊你 eclipse 下方 Servers 卡片裏的服務器,好比個人是 Tomcat v7.0 Server at localhost,雙擊後將彈出一個關於此服務器配置信息的預覽窗口

    3.在該窗口下方有個 Server Options 卡片,將 Publish module contexts to separate XML files 勾上並保存

        4.從新啓動服務器

  s-include.jsp頁面至今空白。從運行後頁面源碼來看,僅包含了included-file.jsp頁面到<title>標籤爲止,後面爲中文字符。

  將include-file.jsp頁面改成:

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
    <h3>被包含的頁面</h3>
    author參數值爲:${param['author']}
</body>
</html>

  則,運行源碼爲:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>使用s:include標籤來包含目標頁面</title>
</head>
<body>
    <h2>使用s:include標籤來包含目標頁面</h2>

    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
    <h3>

    
        
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
    <h3>    

</body>
</html>

  因而可知是中文字符問題,遂再講included-file.jsp改成:

<%@ page language="java" contentType="text/html; charset=GBK"
    pageEncoding="GBK"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
    ${param['author']}
</body>
</html>

  運行頁面終於:

      

  相對源爲:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>使用s:include標籤來包含目標頁面</title>
</head>
<body>
    <h2>使用s:include標籤來包含目標頁面</h2>

    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
    
</body>
</html>

    
        
    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Insert title here</title>
</head>
<body>
    yeeku
</body>
</html>    

</body>
</html>

    未解疑問,爲什麼中文字符不可行?

  修改兩jsp頁面爲UTF-8編碼

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>

  故而運行效果如期,

      

    後續:研究UTF-8與GBK編碼的區別。

相關文章
相關標籤/搜索