1、chat.properties 一般都写成key,value的形式,注释用#。
#Generated by ManageChatServlet
#Mon Apr 23 11:15:57 GMT+05:30 2001
Jsp=Discussion about JSP can be made here.
Java=Talk about java and related technologies like J2EE.
ASP=Discuss about Active Server Pages related technologies like VBScript and JScript etc.
Web_Designing=Any discussion related to HTML, JavaScript, DHTML etc.
StartUp=Startup chat room. Chatter is added to this after he logs in.
2、这是一个servlet中的初始化方法,在web.xml中配置,只要tomcat容器起动,就执行这个初始化方法。
public void init() throws ServletException
{ Properties props = null;
try
{
String path = "";
//加载web.xml中的参数,properties的文件名
path = "/WEB-INF/"+getServletContext().getInitParameter("chatpropertyfile");
String realPath;
realPath = getServletContext().getRealPath(path);
if (realPath != null)
{
InputStream fis = new FileInputStream(realPath);
props = new Properties();
props.load(fis);
Enumeration keys = props.keys();
while (keys.hasMoreElements())
{
String roomName = (String)keys.nextElement();
String roomDescr = (String)props.getProperty(roomName);
addNewRoom(rooms, roomName, roomDescr);
}
fis.close();
getServletContext().setAttribute("chatroomlist", rooms);
System.err.println("Room List Created");
}
else
{
System.out.println("Unable to get realpath of chatproperty file " + path + ".\nCheck that application war file is expanded and file can be read.\nChat application won't work.");
}
}
catch(FileNotFoundException fnfe)
{
System.err.println("Properites file not found:" + fnfe.getMessage());
}
catch(IOException ioe)
{
System.out.print("Unable to load Properties File: " + ioe.getMessage());
}
}
3、在web.xml中,参数可以这样写在xml,我要记一下的。。
<context-param>
<param-name>chatpropertyfile</param-name>
<!-- Name of the chat properties file. It contains the name and description of rooms.
-->
<param-value>chat.properties</param-value>
</context-param>
<context-param>
<param-name>saveRooms</param-name>
<!-- The value of saveRooms can be set to true or false.
If true then all new rooms added by users will be saved in chat.properties files.
Default is false.
-->
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>adminEmail</param-name>
<!-- Add an e-mail address of the administrator of this web site. -->
<param-value>admin@website.com</param-value>
</context-param>
下面这段中<load-on-startup>1</load-on-startup>是让tomcat一起动,就加载这个servlet。
当值为0或者大于0时,表示容器在应用启动时就加载这个servlet;
当是一个负数时或者没有指定时,则指示容器在该servlet被选择时才加载。
正数的值越小,启动该servlet的优先级越高。
<servlet>
<servlet-name>manageChat</servlet-name>
<servlet-class>sukhwinder.chat.servlet.ManageChatServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
上传一个我在国外的网上下载的用jsp+servlet实现的聊天系统,自认为很有参考价值。。
chat.rar是不用IDE的版本
chat-myeclipse.rar是myeclipse的版本。
分享到:
相关推荐
在javascript文件中读取properties文件需要的插件jquery.i18n.properties-min-1.0.9.js
NULL 博文链接:https://960432397.iteye.com/blog/1680661
IDEA WEB项目启动不加载application.properties配置文件,yml配置文件是否也会不加载未尝试,如果有遇到的可以尝试一下。
jquery.i18n.properties-min-1.0.9 主要用于国际化和读取properties文件
Eclipse国际化插件 读取 .properties的中文文件
在Android Studio项目里面有个local.properties文件,这个文件可以放一些系统配置。比如:sdk路径、ndk路径。 ndk.dir=D\:\\soft\\android-ndk-r10e sdk.dir=D\:\\soft\\SDKandroidStudio 当然我们也可以在local....
主要介绍了Python实现读取Properties配置文件的方法,结合实例形式分析了Python读取Properties配置文件类的定义与使用相关操作技巧,需要的朋友可以参考下
c#操作properties,读写配置文件,非常方便,几行代码就搞定
jquery.i18n.properties-min-1.0.9.js前端国际化文件,项目中用到的前端国际化文件。 $.i18n.properties( { name : 'web_i18n', // Resource name path : '/resources/i18n/', //Resource path cache : true, mode :...
NULL 博文链接:https://zhousheng193.iteye.com/blog/1195903
NULL 博文链接:https://960432397.iteye.com/blog/1963687
标准三层结构。...通过读取外部.properties配置文件获取数据库连接字符串连接数据库并进行数据库操作。 附有详细的说明,我的日食项目直接导入。 赠送3752条中英文对照句子,这些句子相信会成为很多人座右铭。
主要介绍了Java读写.properties文件解决中文乱码问题,非常具有实用价值,需要的朋友可以参考下
js读取properties文件,很好用的。js读取properties文件,很好用的。js读取properties文件,很好用的。js读取properties文件,很好用的。
主要介绍了mybatis 使用jdbc.properties文件设置不起作用的解决方法,需要的朋友可以参考下
ConfigFile configfile = ConfigFile.getInstance("ipConfig123.properties"); String ip = configfile.getkeyvalue("ip"); 可以取出ipConfig123.properties 文件中IP的内容
主要介绍了java用类加载器的5种方式读取.properties文件,详细的介绍了这5种方法,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
今天小编就为大家分享一篇关于Java语言读取配置文件config.properties的方法讲解,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧