java流读取及标签的制作

JAVA中获取项目文件路径
1 String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
  ResourceBundle res = ResourceBundle.getBundle("application"); 
  String name =res.getString("name").trim();
2 加载文件
       String data=""
 if(StringUtils.isBlank(data)){
   String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
   FileReader fr = null;
   BufferedReader br = null;
   try {
    fr = new FileReader(path+"/data.text");
    br = new BufferedReader(fr);
    while(br.ready()){
     JSP_TEMP += br.readLine()+"\n";
    }
   } catch (Exception e) {
    e.printStackTrace();
   }finally{
    path = null;
    try {
     br.close();
     fr.close();
    } catch (IOException e) {
     e.printStackTrace();
    }
    
   }
  }
<form action="" method="" name="" enctype="multipart/form-data">
 MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
 MultipartFile file = multipartRequest.getFile("imgFile");
File.separator
//获取文件输出流
FileOutputStream fos = new FileOutputStream(savePath + newFileName);
//获取内存中当前文件输入流        
InputStream in = file.getInputStream();
byte[] buffer = new byte[1024];
try {
 int num = 0;
 while ((num = in.read(buffer)) > 0) {
  fos.write(buffer, 0, num);
 }
} catch (Exception e) {
 e.printStackTrace();
}finally{
 in.close();
 fos.close();
}

=====================================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE taglib PUBLIC "-//Sun Microsystems,
Inc.//DTD JSP Tag Library 1.1//EN" "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
 <tlibversion>1.0</tlibversion>
 <jspversion>1.1</jspversion>
 <shortname>zd</shortname>
 <uri>http://www.zzstxx.com/taglib</uri>

 <tag>
  <name>page</name> <!-- 定义标签名 -->
  <tagclass>com.**</tagclass><!-- 定义标签处理类 -->
 </tag>
 
 <tag>
  <name>page2</name>
  <tagclass>com.**</tagclass>
  <attribute>
   <name>name</name>
   <required>true</required><!-- //属性是否必须. -->
  </attribute>
 </tag>
</taglib>
java
public class ** extends TagSupport
public int doEndTag() throws JspException {
 pageContext.getOut().println(outStr.toString());
        return (EVAL_PAGE);
}
public class **  extends SimpleTagSupport
public void doTag()throws JspException,IOException{
getJspContext().setAttribute("data", data);
}
页面上的应用
<%@ taglib prefix="p" uri="/WEB-INF/page.tld" %>
<p:page />

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值