JAVA常用操作语句----项目中的总结二
来源:互联网 发布:壁虎漫步知乎 编辑:程序博客网 时间:2024/05/21 14:58
- jsp输出格式化后的日期
<fmt:formatDate value="${whiteNumber.crtdate }" pattern="yyyy-MM-dd HH:mm:ss"/>
- 如是model里的list在action中取不到值。可能在该model中的list的setter和getter方式中,使用的可能是lazy加载,改为EAGER即可。
- <s:iterator>标签里还有<s:iterator>标签,里面的标签在使用中如果不显示数据,可能是在外部的标签对应的bean里,对bean里的list的setter和getter方法设置为private,改为public即可 。同样在jsp中用${model.name}取不对值,也可能在bean里的name的setter和getter属性为private ,改为public即可。
- title="hehe hehe" 
可以让alt提示换行。
- iframe标签要加</iframe>关闭标签,不然后面的元素有可能无法显示
- IE下js的数组,“,”后都会有一空格,而FF下则没有。
- 不让链接折行的css:
a {
white-space:nowrap;
}
- js得到父窗口支持IE FF双浏览器
var iframe = parent.document.getElementById("msgrightframe");
var iDoc = iframe.contentDocument?iframe.contentDocument:iframe.contentWindow.document;// Firefox : IE
得到父窗体的iframe
- div自动换行,且只使用y滚动条,兼容ff:
<div id="numDiv" style="display:block;word-wrap:break-word;word-break:break-all;width:495px;height:100px;overflow-y:auto;overflow-x:hidden;border:1px solid;border-color:#7f9db9;padding:2px;"></div>
- 判断session是否过期,并执行某函数
function isSessionOut(fun)//fun:session未过期时执行的函数名
{
var myConn = new XHConn();
if (!myConn) alert("XMLHTTP不能用,请用更新的浏览器.");
var fnWhenDone = function (oXML) {
var ret = oXML.responseText;
if(ret.indexOf('~~') != -1)
{
if(parent!=null)
parent.window.location = '/';
else
window.location = '/';
}
else
{
if(fun!=null && fun!="")
eval(fun);
}
};
myConn.connect("/users/showchangepwd.do", "POST","", fnWhenDone);
}
(showchangepwd.do指向的jsp页面包含~~字符)
使用方法1、onclick="openNew2('2','${item.id }')"
function openNew2(num,itemid)
{
isSessionOut("openNew('"+num+"','"+itemid+"')");
}
2、onclick="isSessionOut();"
3、onclick="isSessionOut('goremove()')"
- 不同浏览器使用不同的css
if(window.navigator.userAgent.indexOf("MSIE")>=1){
//如果浏览器为IE
setActiveStyleSheet("ie.css");
}
else if(window.navigator.userAgent.indexOf("Firefox")>=1){
//如果浏览器为Firefox
setActiveStyleSheet("ie.css");
}
else{
//如果浏览器为其它
setActiveStyleSheet("ie.css");
}
function setActiveStyleSheet(filename){
document.write("<link href=/"/images//"+filename+"/" type=/"text//css/" rel=/"stylesheet/">");
}
- 复制文件
public static void copyfile(String pathSrc,String pathDest) throws IOException
{
FileInputStream fi=new FileInputStream(pathSrc);
FileOutputStream fo=new FileOutputStream(pathDest);
byte data[]=new byte[fi.available()];
fi.read(data);
fo.write(data);
fi.close();
fo.close();
}
- JAVA替换字符
java:line = line.replaceAll(" ", "");
line = line.replaceAll(";", ";");
line = line.replaceAll("/t", "");//去除tab
- 避免lastIndexOf异常
if (selectedNo.lastIndexOf(",") == selectedNo.length() - 1)
{
selectedNo.substring(0, selectedNo.length() - 1);
}
可改为:
if (selectedNo. endsWith (","))
{
selectedNo.substring(0, selectedNo.length() - 1);
}
lastIndexOf函数有可能抛出StringIndexOutOfBoundsException
- td高度可根据文字多少自适应
IE下去掉table标签的样式(table-layout: fixed;)
- dhtmlTree:Tooltips设置
有三种方法去设置tooltip :
使用结点的label("text"item结点的text属性)作为tooltip - enableAutoTooltips(mode) - 默认为false
使用item结点的"tooltip"属性作为tooltip(如果此属性被设置了则默认使用此方法)
使用setItemText(itemId,newLabel,newTooltip) 方法
- 可以在myeclipse切换到多个tomcat中的其它tomcat,切换到相应tomcat后,再部署项目到服务器上。
- 图片载入后自适应设置的尺寸
<IMG onload="javascript:if(this.width>700) {this.height=(700)*this.height/this.width;this.width=700}" border=1>
- 通过getHibernateTemplate获得一对象时,调用该对象的list属性对应的get方法,即可在该对象中加载此list
public CtMmsMessage getMessage(long msgid) throws Exception {
CtMmsMessage m = (CtMmsMessage) getHibernateTemplate().get(CtMmsMessage.class, msgid);
if (m == null) return null;
m.getReceiver(); //别忘了触发一下加载
m.getFramelist().size(); //别忘了触发一下加载
return m;
}
- 在sql语句中的join和where中用到的字段,建立索引,这样可以大幅提高查询速度。项目证明,对于大数据量统计,可提高百倍速度。
- 提供转换编码后的供下载用的文件名 ,解决IE、firefox及linux环境下下载文件中文名乱码问题。
public String getDownloadFileName(String nameStr)
{
String downFileName = nameStr;
try {
ActionContext ctx = ActionContext.getContext();
HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST);
String agent = request.getHeader("USER-AGENT");
if (null != agent && agent.indexOf("MSIE") != -1) {// ie
downFileName = java.net.URLEncoder.encode(downFileName, "UTF-8");
} else {// firefox
downFileName = new String(downFileName.getBytes("UTF-8"), "ISO8859-1");
}
} catch (UnsupportedEncodingException e) {
//e.printStackTrace();
downFileName="unknow.xls";
}
return downFileName;
}
- JAVA常用操作语句----项目中的总结二
- JAVA常用操作语句----项目中的总结一
- JAVA常用操作语句----项目中的总结五
- java中的IO操作总结(二)
- Java中的IO操作总结(二)
- java中的IO操作总结(二)
- Java中的常用语句
- Java Jxl Excel 操作总结5(项目实例二)
- 个人项目-密码管理-总结二(常用SQL语句汇总)
- java中的io系统总结及一些常用的操作
- MySQL数据库常用SQL语句总结二
- js中的DOM常用语句总结
- Git常用操作命令总结(二)
- java中的时间操作 二
- java中的时间操作 二
- java中的时间操作 二
- 工作项目总结(二)之数据库操作
- Java中的常用类总结
- How can I throw an exception without losing the original stack trace information in .NET?
- 考过了系分又如何?
- 开始写博客了(开篇语)
- 时间管理三招
- 转在 Visual C++ 中使用内联汇编
- JAVA常用操作语句----项目中的总结二
- 关于Hibernate中对集合类型的映射
- Servlet多线程安全问题
- background-image(CSS) url 路径问题
- JS Date相关(转载)
- SMARTFORMS 小计
- [易飞]如何制作自定义报表
- PL/SQL使用备忘
- ASP.NET技术的学习顺序问题