相关疑难解决方法(0)

servletcontext.getRealPath("/")是什么意思,什么时候应该使用它

在以下代码段中:

ServletContext context = request.getServletContext();
String path = context.getRealPath("/");
Run Code Online (Sandbox Code Playgroud)

是什么/在方法getRealPath()代表什么呢?我应该什么时候使用它?

java servlets realpath

60
推荐指数
1
解决办法
11万
查看次数

在Java Web应用程序文件夹中创建文件并存储

我想创建一个xml文件并存储在我的Spring Mvc Web应用程序的文件夹中.

我可以用我的应用程序的根目录 request.getContextPath()

我如何获得应用程序的相对路径,以便它可以在应用程序文件夹的位置独立地在任何机器上工作?

喜欢 C:/folder/folder/MYAPPLICATIONROOTFOLDER

java spring-mvc

4
推荐指数
1
解决办法
1万
查看次数

java中如何将base64转换为MultipartFile

我有个问题。我想转换BufferedImage为 MultipartFile。首先,在我的 UI 上发送base64到服务器,在我的服务器上,我转换为BufferedImage之后我想要将 BufferedImage 转换为 MultipartFile 并保存在本地存储上。这是我的方法:

@PostMapping("/saveCategory")
    @ResponseStatus(HttpStatus.OK)
    public void createCategory(@RequestBody String category ) {



        BufferedImage image = null;
        OutputStream stream;
        byte[] imageByte;
        try {
            BASE64Decoder decoder = new BASE64Decoder();
            imageByte = decoder.decodeBuffer(category);
            ByteArrayInputStream bis = new ByteArrayInputStream(imageByte);
            image = ImageIO.read(bis);
            bis.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    String fileName = fileStorageService.storeFile(image );
Run Code Online (Sandbox Code Playgroud)

我的存储方法:

public String storeFile(MultipartFile file) {
        // Normalize file name
        String fileName = StringUtils.cleanPath(file.getOriginalFilename());
        try {
            // Check …
Run Code Online (Sandbox Code Playgroud)

base64 spring-boot

3
推荐指数
1
解决办法
2万
查看次数

标签 统计

java ×2

base64 ×1

realpath ×1

servlets ×1

spring-boot ×1

spring-mvc ×1