spring解析Properties文件

1、在配置文件中配置

 

applicationContext-upload.xml

 

<? xml version = "1.0" encoding = "UTF-8" ?>

< beans xmlns = "http://www.springframework.org/schema/beans"

    xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"

    xsi:schemaLocation = "http://www.springframework.org/schema/beans

           http://www.springframework.org/schema/beans/spring-beans-2.5.xsd" >

    < bean id = "multipartResolver" class = "org.springframework.web.multipart.commons.CommonsMultipartResolver" >

       <!-- 设置上传文件大小的参数 one of the properties available; the maximum file size in bytes -->

       < property name = "maxUploadSize" value = "100000" />

    </ bean >

</ beans >

 

2、在项目中添加 commons-io.jar、commons-fileupload.jar包

或者在maven配置中添加这两个包

       < dependency >

           < groupId > commons-fileupload </ groupId >

           < artifactId > commons-fileupload </ artifactId >

           < version > 1.2 </ version >

       </ dependency >

       < dependency >

           < groupId > commons-io </ groupId >

           < artifactId > commons-io </ artifactId >

           < version > 1.4 </ version >

       </ dependency >

 

3、Controller类中的方法

    @RequestMapping ( "/uploadProperties" )

    public String uploadProperties( @RequestParam () MultipartFile file)

           throws IOException {

       if (!file.isEmpty()) {

           InputStream in = file.getInputStream();

           Properties p= new Properties();

           p.load(in);

          

           Enumeration<?> keys = p.propertyNames();

          

           while (keys.hasMoreElements()){

              String key = (String) keys.nextElement();

              String value = p.getProperty(key);

             

              System. out .println(key + " " + value);

           }

 

       }

      

       return "redirect:/goUploadProperties" ;

    }

 

4、html文件中的代码

       < form method= "post" action= "$rc.contextPath/uploadProperties" enctype= "multipart/form-data" >

          < input type= "file" name= "file" />

          < input type= "submit"   value= "upload" />

        </ form >

 

参考资料:

上传

http://doc.javanb.com/spring-framework-reference-zh-2-0-5/ch13s08.html

http://teddywang.javaeye.com/blog/652089

 

java解析properties文件

http://shengmo8611.javaeye.com/blog/832516

首先了解一下properties文件
propertie是文件一般是用来保存键值对数据的比如:
username=xiaoqiang
password=xiaopohai
这样的形式
java解析properties文件首先要有核心对象
Properties p=new Properties();
解析文件首先降文件读取到程序中
FileInputStream fis=new FileInputStream(String filename);
读取p.load(fis);
然后可以使用
p.propertyNames();得到所有的key值(得到的是Enumeration 类型)
p.getProperty(key);可以得到指定的value值

 

spring中防止重复提交

http://elf8848.javaeye.com/blog/875830

通过redirect:url 防止表单重复提交

return "redirect:/index.jsp";





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值