您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

Servlet中获取资源的方式

2024/11/13 7:47:00发布22次查看
package com.test; import java.io.file; import java.io.*; import java.io.fileinputstream; import java.io.ioexception; import java.io.inputstream; import java.io.printwriter; import java.util.properties; import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; public class getzy extends httpservlet { /** * the doget method of the servlet. <br> * * this method is called when a form has its tag value method equals to get. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws servletexception if an error occurred * @throws ioexception if an error occurred */ public void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { string path=this.getservletcontext().getrealpath("/web-inf/classes/mess.properties"); //项目里src的文件都在tomcat的web-inf/classes的文件夹下 system.out.println(path); //获取文件的路径 fileinputstream in=new fileinputstream(new file(path)); properties prop=new properties(); prop.load(in); //import java.util.properties;需要导入这个包 //用load方法加载文件 system.out.println(prop.getproperty("id")); system.out.println(prop.getproperty("password")); //通过getproperty()获取内容 } }
以上就是servlet中获取资源的方式的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product