freemark、jsp&css

 

**************************************************************freemark相关**************************************************************
<#list Request['supportPayTypeList']?keys as key>     //后台数据时放在request里的map集合,map里放map
<#if Request['supportPayTypeList'][key].state=='close'>
            <li id="pay__${key}" style="display:block" class="payTypeSelect" payTypeName="${key}"><b class="name">${Request['supportPayTypeList'][key].name}</b><i class="wy_de">${Request['supportPayTypeList'][key].desc}</i></li>
<#else>
</#if>

alert("${myTextKey!"myText2"}");
alert($("#${myTextKey!"myText2"}").val());           
${(xx!'')?upper_case?html}   转换成大写输出

<#assign defaultBindingTel="">
<#if Request['bindCardList']?exists && Request['BindCardSize'] gt 0>
<#list animals as being>   //animals是后台存放map的list集合
   <tr><td>${being.name}<td>${being.price} Euros
</#list>

<#if orderInfoPo?exists && tblPackageInfo?exists>
${createTimeStr?substring(0,4)}
<#if (rateInfoPoJson?size > 0)>
${hk.payTime!""}

${preYear?c} 数字大于1000后freeMark会显示为1,000,用c转换

var evalStr=payTypeName+"_open()";//执行方法
eval(evalStr)
replace(/[ ]/g,"")去空  replace(/s+/g,"")

var bankLst_scancode = ${Request['bankLst_scancode']!'[]'}//json串直接赋值不加引号

 if(top.location != location){//如果当前页面为子页面,则刷新父页面
    top.location.href = location.href;
 }

freeMark 传值及数据回传的写法  另一种为String返回
ModelAndView mav = new ModelAndView();
mav.addObject("zerobuyProduct", zerobuyProductList);//传递的参数为
mav.setViewName("finance/orderDetails");//要跳转到的页面

JSONArray jsonArray = JSONArray.fromObject(zerobuyOrderPoJson); //json串转换jsonArray对象
List<?> myOrdersList = JSONArray.toList(jsonArray); //供前台freeMark遍历 已过时  可直接强转
JSONObject resultObj = JSONObject.fromObject(jsonStr) ;//json串转换json对象  进而由key获取value     toString方法可以将对象转换成串

${mft('${orders.payMoney}','#,##0.00#','f2y')}

*************************************************************jsp页面相关*****************************************************************

<jsp:include page="/commonTop.html " flush="true"/>,通过这种方式引用的话,当引用它的jsp页面被访问的时候会被动态的引入
<%@ include file=“/commonTop.html”%>这种方式引用文件的话,当引用它的JSP转换成Servlet时引入就被指定,内容后续访问过程中保持不变

String siteAccount =  request.getParameter("data1");//商户号
        String orderNo = request.getParameter("data2");//订单编号
        List list = new ArrayList();
        Map map = new HashMap();
        map.put("name", "namevalue");
        Map map2 = new HashMap();
        map2.put("name", "namevalue2");
        list.add(map);
        list.add(map2);
        JSONArray jarray =  JSONArray.fromObject(list);   
        try {
            response.setContentType("text/html" + ";charset=UTF-8");
            response.setHeader("Pragma", "No-cache");
            response.setHeader("Cache-Control", "no-cache");
            response.setDateHeader("Expires", 0);
            response.getWriter().write(jarray.toString());
            response.getWriter().flush();
        } catch (IOException e) {
            e.printStackTrace();
        }

function myAjax(){
    $.ajax({
      type:"POST",
      url:"myAjax.dhtml",
      data:{"data1":"data1value","data2":"data1value2"},
      dataType:"json",
      success:function(msg){
        alert(msg[0]);
        alert(msg[0].name);
      }
    });
}


 
<div style="margin-left: ; 50;height: 60;display: inline;" ></div>
<div style="margin-left: ; 50;height: 60;display: inline;"></div>
<div style="margin-left: ; 50;height: 60;display: inline;"></div>
 
window.parent.location="";    WebContext.getMessage(new Locale("zh_CN"), appRes.getResNum())

<td style="25%;overflow:hidden ;white-space: nowrap;word-break:"   >
     <div style="margin-left: ; 50;height: 60;display: inline;" ></div>
     <div style="margin-left: ; 50;height: 60;display: inline;"></div>
     <div style="margin-left: ; 50;height: 60;display: inline;"></div>
</td>

white-space:nowrap强制在一行显示,overflow:hidden超出部分隐藏,必须在table-layout:fixed下生效
text-overflow:ellipsis超出部分用...显示


<td style="word-break:break-all">超出列的文字换行
<meta http-equiv="X-UA-Compatible"content="IE=9; IE=8; IE=7; IE=EDGE" />
margin-top: 30px该元素头部离外部上一个元素之间的距离
table-layout:fixed列的宽度不取决于内容,在于第一列的宽度设置  (列宽度用%比,利于隐藏超出部分,表不会被内部元素撑开)
margin-left负值代表本元素在相对元素之下(隐藏效果)
white-space:nowrap强制在一行显示

<style type="text/css">
          table {border-right:1px solid red;border-bottom:1px solid red}             
          td { 100;border-left:1px solid red;border-top: 1px solid red}
</style>

<table  border="0"  cellspacing="0" cellpadding="0">
 
$("ul[class^='result-wrap']:visible").css("display","none");
$("ul[class^='result-wrap']").css("display","none");
$('.software-expand').html("展开");

//var url = "<%=path%>/page/soft/soft.do?method=detail&uuid="+uuid+"";
//window.showModelessDialog(url,window,"dialogWidth:400px;dialogHeight:300px;center:yes;help:no;scroll:auto;");

 dhxWins = new dhtmlXWindows();
                        w1 = dhxWins.createWindow("w1",500, 130, 420, 350);
                        w1.setText("软件信息");
                             w1.setModal(false);
                             w1.button("close").attachEvent("onClick", function(){
                                     dhxWins.window("w1").close();
                        });
                        w1.attachURL("<%=path%>/page/soft/soft.do?method=detail&uuid="+uuid+"");
                       

var url = "<%=path%>/page/soft/soft.do?method=detail&uuid="+uuid+"";
window.showModelessDialog(url,window,"dialogWidth:400px;dialogHeight:300px;center:yes;help:no;scroll:auto;");

整行滚动
<marquee id='marquee_' direction='left' align='bottom' width='98%' onmouseout='this.start()' onmouseover='this.stop()' scrollamount='2' scrolldelay='4'>sdfsdfsdfsssssssssssssssssssssssssssssssssssssss</marquee>


//var regex = /d{1}/;
                      var regex = /^([0-9]|[a-zA-Zu4E00-u9FA5]|[_])+$/;
                       var regex = /^w+$/;
                     var str = "2323sdf2s__sd上的f";
                      alert(regex.test(str)+"  "+str.match(regex));
                      str = str.replace(/s/g,"");

JSP 页面缓存以及清除缓存

一、概述

    缓存的思想可以应用在软件分层的各个层面。它是一种内部机制,对外界而言,是不可感知的。

    数据库本身有缓存,持久层也可以缓存。(比如:hibernate,还分1级和2级缓存)

    业务层也可以有缓存(但一般来说,这是一个过程域,不会设缓存)。

    表现层/数据服务层(传统web的表现层)也可以设置缓存(jsp cache 就是这一层,实现在app server上的缓存机制)

    另外Browser也有缓存(如IE)这个大家也都知道(实现在 web server 上的缓存机制)。越上层的缓存效果越好,越底层的缓存影响越深远。

 
二、缓存实现(浏览器缓存当前访问的JSP动态页面)

(一)、服务端方法:

<%   

response.setHeader("Pragma","No-cache");    

response.setHeader("Cache-Control","no-cache");    

response.setDateHeader("Expires", -10);   

%>  

(二)、客户端方法:

meta是用来在HTML文档中模拟HTTP协议的响应头报文。meta 标签用于网页的<head>与</head>中,

meta 标签的用处很多。meta 的属性有两种:name和http-equiv。name属性主要用于描述网页,对应于

content(网页内容),以便于搜索引擎机器人查找、分类(目前几乎所有的搜索引擎都使用网上机器人

自动查找meta值来给网页分类)。这其中最重要的是description(站点在搜索引擎上的描述)和

keywords(分类关键词),所以应该给每页加一个meta值。比较常用的有以下几个:

name 属性

1、<meta name="Generator" contect="">用以说明生成工具(如Microsoft FrontPage 4.0)等;

2、<meta name="KEYWords" contect="">向搜索引擎说明你的网页的关键词;

3、<meta name="DEscription" contect="">告诉搜索引擎你的站点的主要内容;

4、<meta name="Author" contect="你的姓名">告诉搜索引擎你的站点的制作的作者;

5、<meta name="Robots" contect="all|none|index|noindex|follow|nofollow">

 
其中的属性说明如下:

设定为all:文件将被检索,且页面上的链接可以被查询;

设定为none:文件将不被检索,且页面上的链接不可以被查询;

设定为index:文件将被检索;

设定为follow:页面上的链接可以被查询;

设定为noindex:文件将不被检索,但页面上的链接可以被查询;

设定为nofollow:文件将不被检索,页面上的链接可以被查询。

 
http-equiv属性

1、<meta http-equiv="Content-Type" contect="text/html";charset=gb_2312-80">

和 <meta http-equiv="Content-Language" contect="zh-CN">用以说明主页制作所使用的文字以及语言;

又如英文是ISO-8859-1字符集,还有BIG5、utf-8、shift-Jis、Euc、Koi8-2等字符集;

2、<meta http-equiv="Refresh" contect="n;url=http://yourlink">定时让网页在指定的时间n内,跳转到页面http;//yourlink;

3、<meta http-equiv="Expires" contect="Mon,12 May 2001 00:20:00 GMT">可以用于设定网页的到期时间,

一旦过期则必须到服务器上重新调用。需要注意的是必须使用GMT时间格式;

4、<meta http-equiv="Pragma" contect="no-cache">是用于设定禁止浏览器从本地机的缓存中调阅

页面内容,设定后一旦离开网页就无法从Cache中再调出;

5、<meta http-equiv="set-cookie" contect="Mon,12 May 2001 00:20:00 GMT">cookie设定,如果

网页过期,存盘的cookie将被删除。需要注意的也是必须使用GMT时间格式;

6、<meta http-equiv="Pics-label" contect="">网页等级评定,在IE的internet选项中有一项内容

设置,可以防止浏览一些受限制的网站,而网站的限制级别就是通过meta属性来设置的;

7、<meta http-equiv="windows-Target" contect="_top">强制页面在当前窗口中以独立页面显示,

可以防止自己的网页被别人当作一个frame页调用;

8、<meta http-equiv="Page-Enter" contect="revealTrans(duration=10,transtion= 50)">和

<meta http-equiv="Page-Exit" contect="revealTrans(duration=20,transtion =6)">设定进入和离

开页面时的特殊效果,这个功能即FrontPage中的“格式/网页过渡”,不过所加的页面不能够是一个
frame页面。

三、缓存应用

(一)、防止JSP页面缓存为了防止浏览器缓存当前访问的JSP动态页面,可以采用如下的方式进行设置:

<%
// 将过期日期设置为一个过去时间
response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");
// 设置 HTTP/1.1 no-cache 头
response.setHeader("Cache-Control", "no-store,no-cache,must-revalidate");
// 设置 IE 扩展 HTTP/1.1 no-cache headers, 用户自己添加
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
// 设置标准 HTTP/1.0 no-cache header.
response.setHeader("Pragma", "no-cache");
%>

当然,每一个页面都包含这些代码会很繁琐,可以通过自定义过滤器(Filter)的方法来处理相关的页面  

(二)、jsp,html 清除页面缓存

1.禁止客户端缓存要在<head>中加入类似如下内容:

<META HTTP-EQUIV="pragma" CONTENT="no-cache">

<META HTTP-EQUIV="Cache-Control" CONTENT="no-cache, must-revalidate">

<META HTTP-EQUIV="expires" CONTENT="Wed, 26 Feb 1997 08:21:57 GMT">

或   
<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">   

2.在服务器的动态网页中禁止缓存,要加入类似如下脚本

response.setHeader("Pragma","No-cache");

response.setHeader("Cache-Control","no-cache");

response.setDateHeader("Expires", 0);  

 

(三)设置有限时间的缓存

    int minutes = 10;

    Date d = new Date();

    String modDate = d.toGMTString();

    String expDate = null;

    expDate = (new Date(d.getTime() + minutes * 60000)).toGMTString();

    response.setHeader("Last-Modified", modDate);

    response.setHeader("Expires", expDate);

    response.setHeader("Cache-Control", "public"); //   HTTP/1.1

    response.setHeader("Pragma", "Pragma"); //   HTTP/1.0  

 

最后如果以上方法都不行的话,就在你的正常的URL后面加上一个尾巴

在JS中就选择

var timestamp = (new Date()).valueOf();  

URL+"&timestamp="+timestamp;

在Java代码中就选择

long timestamp=new Date().getTime();

URL+"&timestamp="+timestamp;

这样的话,你的URL始终都在变化,自然浏览器就得老老实实的进行更新了,它也无缓冲可拿了。



补充:关于.jsp cache的几条建议:

1.jsp cache最好做在过滤器上,把需要缓冲的页面集中在同一个目录下,每次更改只须更改web.xml就可

以完成缓冲设置,这样比较方便.

2.Gzip压缩可以将页面压缩得很小,平均压缩比为1/3,jsp cache的HashMap缓冲压缩后的页面,肯定比没

压缩前更节约内存消耗,并且效率更高.关于Gzip可以参考这个开源项

原文地址:https://www.cnblogs.com/xingminghui/p/4228475.html