1 所有的 .java|.jsp|.html|.xml 源文件均使用utf-8编码格式保存到系统磁盘。
如:在Eclipse中编辑文件,选中文件打开右键菜单选择属性,将文本文件编码设置为其他并选择UTF-8;也可以在
Eclipse——首选项——常规——内容类型中设置各种文件的缺省编码,这样以后所有的文本文件都使用统一编码。
2 在页面显示中文方面 .jsp文件中必须将文件编码格式pageEncoding、<@page>指令中contentType编码格式、<html>的<meta>标签编码格式都设置为utf-8。
如:
<%@ page language="java" pageEncoding="utf-8"%>
<%@ page contentType="text/html;charset=utf-8"%>
<html>
<head>
<title>中文问题</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
</html>
注意: META标签中的编码字符必须是"utf-8",如果不加中划线,则在ie下出现乱码情况,但ie的原文件查看却是中文!
3 把表单提交内容的字符集设为utf-8,在jsp、servlet或者filter中使用request.setCharacterEncoding("utf-8");
此行代码必须写在最前面,如果在此 ......
1 所有的 .java|.jsp|.html|.xml 源文件均使用utf-8编码格式保存到系统磁盘。
如:在Eclipse中编辑文件,选中文件打开右键菜单选择属性,将文本文件编码设置为其他并选择UTF-8;也可以在
Eclipse——首选项——常规——内容类型中设置各种文件的缺省编码,这样以后所有的文本文件都使用统一编码。
2 在页面显示中文方面 .jsp文件中必须将文件编码格式pageEncoding、<@page>指令中contentType编码格式、<html>的<meta>标签编码格式都设置为utf-8。
如:
<%@ page language="java" pageEncoding="utf-8"%>
<%@ page contentType="text/html;charset=utf-8"%>
<html>
<head>
<title>中文问题</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
</html>
注意: META标签中的编码字符必须是"utf-8",如果不加中划线,则在ie下出现乱码情况,但ie的原文件查看却是中文!
3 把表单提交内容的字符集设为utf-8,在jsp、servlet或者filter中使用request.setCharacterEncoding("utf-8");
此行代码必须写在最前面,如果在此 ......
1 所有的 .java|.jsp|.html|.xml 源文件均使用utf-8编码格式保存到系统磁盘。
如:在Eclipse中编辑文件,选中文件打开右键菜单选择属性,将文本文件编码设置为其他并选择UTF-8;也可以在
Eclipse——首选项——常规——内容类型中设置各种文件的缺省编码,这样以后所有的文本文件都使用统一编码。
2 在页面显示中文方面 .jsp文件中必须将文件编码格式pageEncoding、<@page>指令中contentType编码格式、<html>的<meta>标签编码格式都设置为utf-8。
如:
<%@ page language="java" pageEncoding="utf-8"%>
<%@ page contentType="text/html;charset=utf-8"%>
<html>
<head>
<title>中文问题</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
</html>
注意: META标签中的编码字符必须是"utf-8",如果不加中划线,则在ie下出现乱码情况,但ie的原文件查看却是中文!
3 把表单提交内容的字符集设为utf-8,在jsp、servlet或者filter中使用request.setCharacterEncoding("utf-8");
此行代码必须写在最前面,如果在此 ......
1 所有的 .java|.jsp|.html|.xml 源文件均使用utf-8编码格式保存到系统磁盘。
如:在Eclipse中编辑文件,选中文件打开右键菜单选择属性,将文本文件编码设置为其他并选择UTF-8;也可以在
Eclipse——首选项——常规——内容类型中设置各种文件的缺省编码,这样以后所有的文本文件都使用统一编码。
2 在页面显示中文方面 .jsp文件中必须将文件编码格式pageEncoding、<@page>指令中contentType编码格式、<html>的<meta>标签编码格式都设置为utf-8。
如:
<%@ page language="java" pageEncoding="utf-8"%>
<%@ page contentType="text/html;charset=utf-8"%>
<html>
<head>
<title>中文问题</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
</html>
注意: META标签中的编码字符必须是"utf-8",如果不加中划线,则在ie下出现乱码情况,但ie的原文件查看却是中文!
3 把表单提交内容的字符集设为utf-8,在jsp、servlet或者filter中使用request.setCharacterEncoding("utf-8");
此行代码必须写在最前面,如果在此 ......
import java.util.ArrayList;
import java.util.List;
public class FenYe
{
static double allpage=0; //总页数
static double currpage=0; //当前页
static double pagesize=10; //显示行
static int startindex=0; //起始索引
static int endindex=0; //结束索引
static List alldata=null; //分完的数据
/**
* 得到当前页
* @return
*/
public static int getCurrpage() {
return (int)currpage;
}
/**
* 设置当前页
* @param currpage
*/
public void setCurrpage(int currpage) {
currpage = currpage;
}
/**
* 得到页大小(每页显示的行数)
* @return
*/
public stat ......
import java.util.ArrayList;
import java.util.List;
public class FenYe
{
static double allpage=0; //总页数
static double currpage=0; //当前页
static double pagesize=10; //显示行
static int startindex=0; //起始索引
static int endindex=0; //结束索引
static List alldata=null; //分完的数据
/**
* 得到当前页
* @return
*/
public static int getCurrpage() {
return (int)currpage;
}
/**
* 设置当前页
* @param currpage
*/
public void setCurrpage(int currpage) {
currpage = currpage;
}
/**
* 得到页大小(每页显示的行数)
* @return
*/
public stat ......
转自:http://java.chinaitlab.com/Tomcat/33170.html
经常看到jsp的初学者问tomcat下如何配置jsp、servlet和bean的问题,于是总结了一下如何tomcat下配置jsp、servlet和ben,希望对那些初学者有所帮助。
一、开发环境配置
第一步:下载j2sdk和tomcat:到sun官方站(http://java.sun.com/j2se/1.5.0/download.jsp)下载j2sdk,注意下载版本为Windows Offline Installation的SDK,同时最好下载J2SE 1.5.0 Documentation,然后到tomcat官方站点(http://jakarta.apache.org/site/downloads/downloads_tomcat-5.cgi)下载tomcat(下载最新5.5.9版本的tomcat);
第二步:安装和配置你的j2sdk和tomcat:执行j2sdk和tomcat的安装程序,然后按默认设置进行安装即可。
1.安装j2sdk以后,需要配置一下环境变量,在我的电脑->属性->高级->环境变量->系统变量中添加以下环境变量(假定你的j2sdk安装在c:\j2sdk1.5.0):
JAVA_HOME=c:\j2sdk1.5.0
classpath=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;(.;一定不能少,因为它代表当前路径)
path=%JAVA_HOME%\bin
接着可以写一个简单 ......
一:到http://tuckey.org/urlrewrite/ 下载urlrewrite架包(推荐2.6.0)
二:解压所下载的文件,把urlrewrite-2.6.0.jar复制到项目的WebRoot/WEB-INF/lib/目录下
三:把urlrewrite.xml复制到项目的WebRoot/WEB-INF/目录下
四:在web.xml文件中加入以下
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>logLevel</param-name>
<param-value>WARN</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
(UrlRewriteFilter这个可以更改,但是如果要更改的话,就两个UrlRewriteFilter都一起改为相同的字符串,比如说都改为:aaa也是可以的!其实这个在urlrewrite.xml里有说明,仔细看看就知道了!哦,忘了,上面这段代码加到:</welcome-file-list ......
一:到http://tuckey.org/urlrewrite/ 下载urlrewrite架包(推荐2.6.0)
二:解压所下载的文件,把urlrewrite-2.6.0.jar复制到项目的WebRoot/WEB-INF/lib/目录下
三:把urlrewrite.xml复制到项目的WebRoot/WEB-INF/目录下
四:在web.xml文件中加入以下
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
<init-param>
<param-name>logLevel</param-name>
<param-value>WARN</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
(UrlRewriteFilter这个可以更改,但是如果要更改的话,就两个UrlRewriteFilter都一起改为相同的字符串,比如说都改为:aaa也是可以的!其实这个在urlrewrite.xml里有说明,仔细看看就知道了!哦,忘了,上面这段代码加到:</welcome-file-list ......
最近在写JSP的小项目,不想把数据库,数据文件夹路径等配置信息写死在代码中,于是琢磨用xml配置文件的方法,现在将使用心得总结一下:
1.除了引入dom4j.jar包之外,使用XPATH必须引入jaxen.jar包,否则老是报错。(在dom4j的解压文件夹下的lib文件夹中可以找到jaxen.jar)
2.重点:由于是要在tomcat环境之下使用java访问文件夹中的配置文件,所以:
首先要将配置文件放在classes文件夹之下(这点是方便确定文件的路径)
其次,打开文件的时候采用以下方式
reader = new SAXReader();
//采用此方式可以访问绝对路径
doc = reader.read(Thread.currentThread().getContextClassLoader().getResource(fileName));
否则相对路径问题会把你弄疯的!
GOOD LUCK! ......
第1条 How to Write an Equality Method in Java
http://www.artima.com/lejava/articles/equality.html
How to Write an Equality Method in Java
by Martin Odersky, Lex Spoon, and Bill Venners
June 1, 2009
Summary
This article describes a technique for overriding the equals method that preserves the contract of equals even when subclassses of concrete classes add new fields.
In Item 8 of Effective Java1, Josh Bloch describes the difficulty of preserving the equals contract when subclassing as a “fundamental problem of equivalence relations in object-oriented languages.” Bloch writes:
There is no way to extend an instantiable class and add a value component while preserving the equals contract, unless you are willing to forgo the benefits of object-oriented abstraction.
Chapter 28 of Programming in Scala shows an approach that allows subclasses to extend an instantiable class, add a value component, and nevertheless preserve the equals contract. Althou ......
第1条 How to Write an Equality Method in Java
http://www.artima.com/lejava/articles/equality.html
How to Write an Equality Method in Java
by Martin Odersky, Lex Spoon, and Bill Venners
June 1, 2009
Summary
This article describes a technique for overriding the equals method that preserves the contract of equals even when subclassses of concrete classes add new fields.
In Item 8 of Effective Java1, Josh Bloch describes the difficulty of preserving the equals contract when subclassing as a “fundamental problem of equivalence relations in object-oriented languages.” Bloch writes:
There is no way to extend an instantiable class and add a value component while preserving the equals contract, unless you are willing to forgo the benefits of object-oriented abstraction.
Chapter 28 of Programming in Scala shows an approach that allows subclasses to extend an instantiable class, add a value component, and nevertheless preserve the equals contract. Althou ......