SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:You can return Resource, wrapped in ResponseEntity if needed. The Resource implementation could be InputStreamResource, FileSystemResource or something else.
One note about your input - make sure to limit what the filename and user path variables can contain. For instance, make sure that they cannot contain ... If you do it will become possible to get access to files outside of the user's directory. For instance, if filename was ../../../../../../../etc/passwd, it would go all the way up to the root, then get etc/passwd. It would also be wise to prevent / in file names; right now that's not a risk, but if you ever switch to Path then using resolve or Paths.get will accept absolute files (File does not, I've checked when I ran into an issue because I expected it would).
Junilu Lacar wrote:Why create nondescript variable names like param1 and param2 and messages that leak the structure of your implementation code ("Parameter not found in first if!"). It's almost as if you're purposely trying to obscure the intent of the perfectly fine names of filename and user. This carries over to lines 10 and 13. Wouldn't this be easier to understand instead:
Also, why not use Spring Validation instead? https://docs.spring.io/spring/docs/4.1.x/spring-framework-reference/html/validation.html
This comment screams "Inject the value instead of hard-coding it!":
And the intent of that code is obfuscated by your nondescript variable name, param2.
Jack Tauson wrote:Is there something in the newer version of spring boot framework that I could use instead of using older servlet APIs in my code?
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions
Rob Spoor wrote:
Jack Tauson wrote:Is there something in the newer version of spring boot framework that I could use instead of using older servlet APIs in my code?
I wouldn't call it new, but Spring MVC (which you're already using) can be used in almost all cases without needing access to HttpServletRequest and/or HttpServletResponse.
SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6 - OCEJPAD 6
How To Ask Questions How To Answer Questions