开发者

Is it necessary to adhere to Java EE directory conventions in the webroot?

开发者 https://www.devze.com 2023-03-13 12:59 出处:网络
开发者_如何学PythonI\'m working on a Java EE project right now, and I love it. Much nicer (IMO) than PHP. I was looking for a list of Java EE coding conventions just to make sure I was adhering to the

开发者_如何学PythonI'm working on a Java EE project right now, and I love it. Much nicer (IMO) than PHP. I was looking for a list of Java EE coding conventions just to make sure I was adhering to them. I ran across this link:

http://java.sun.com/developer/technicalArticles/javaserverpages/code_convention/

This page states that I should have directories such as /js, /css, and /WEB-INF/jspf under the webroot (/web) but I HATE that. I would rather use meaningful directory names such as /scripts, /styles, and /fragments, like I would with PHP.

Can S.O. shed some light on this?


It's just a folder naming convention. You don't need to strictly adhere this, as long as you don't use folder names like /tkjbwnkjh instead of /js or /scripts or /javascript, etc. Keep it self-documenting so that future codebase maintainers won't rant on you.

On a related note to the JSP code conventions, much more important are real code conventions, see also: How to avoid Java code in JSP files?


The names that you choose for your various subdirectories are really a matter of choice. Remember to pick names that will work for others, though. Even if your project is small and personal, the habits you form will carry-over into projects that you share with development teams in the future.

I would recommend that you choose /WEB-INF/fragments instead of /fragments, since files in /fragments can be served directly to a browser... which may not make sense if the file contains markup that is context dependent.

Files that are in /WEB-INF are accessible to your Java code but are not directly accessible from a browser. Your code can read the files and use them... but the user will not be able to get to them by typing 'http://foo.com/WEB-INF/fragments/header.jspf.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号