#Java #Servelt #IDEA
在Servelt 中引用IOUtils方法报错的解决方法以及代码如下图(仅供参考):
//第一步代码
FileInputStream fis=new FileInputStream("此处填写你的使用的图片的绝对路径");
ServletOutputStream os = response.getOutputStream();
IOUtils.copy(fis,os);
fis.close();
//第二步
import org.apache.commons.io.IOUtils;
完整参考代码(仅供参考):
package
com.example.demo4;
import java.io.*;
import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import org.apache.commons.io.IOUtils;
@WebServlet("/asd")
public class asd extends HttpServlet {
private String message;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
IOException {
FileInputStream fis=new FileInputStream("D:\\wangjiashuo\\A23-大三上\\A23-Java Web\\IntelliJ IDEA 2023.2.1\\TextServlet\\demo4\\XE4.jpg");
ServletOutputStream os = response.getOutputStream();
IOUtils.copy(fis,os);
fis.close();
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws
IOException {
this.doGet(request, response);
}
}
项目包
链接:https://pan.baidu.com/s/1mXZiJEMwtO32EjGLNiC3TQ?pwd=asda
提取码:asda