How can you check if a file exists before including/importing it in JSP?

前端 未结 2 1825
迷失自我
迷失自我 2020-12-17 14:47

Assuming that requestScope.importMe is expecting a path to a JSP file


    

        
2条回答
  •  失恋的感觉
    2020-12-17 15:37

    Put it in a c:catch tag. It will catch any thrown Exception for you.

    
        
    
    
        Error: ${e.message}
    
    

    I must however admit that I don't like the c:catch approach. It's abusing exceptions to control the flow. If you can, rather do this job in a servlet or JavaBean instead with help of File#exists() (and ServletContext#getRealPath()).

提交回复
热议问题