zoukankan      html  css  js  c++  java
  • struts2学习笔记①

    在学习Struts2的include标签中出现了问题

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

          使用Struts2 jar包如下:

              

      有s-include.jsp页面如下:

    <%@ 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页面,结果

              

      得到源码为:

    <!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.

      解决方法:

        ①. 注释<!--  -->

        ②. 将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编码的区别。

  • 相关阅读:
    [bzoj 2460]线性基+贪心+证明过程
    [Wc2011] Xor
    [BZOJ2844]线性基+xor本质不同第K大
    洛谷3857 [TJOI2008]彩灯
    HDU3949 异或线性基
    hdu3062 party --2-sat
    KM算法详解+模板
    Hopcroft-Karp算法
    bzoj 1135: [POI2009]Lyz
    hall定理的证明
  • 原文地址:https://www.cnblogs.com/issa/p/3616562.html
Copyright © 2011-2022 走看看