So it stands for Java Server Pages, gets compiled into a .java file,
seems like Java should be the primary language, but Eclipse
recognizes html as the primary language and Java code has to be
embedded with <% %> which people don't recommend. Assuming there's no
good frameworks available like Spring or Angular, what's the best way
to make jsp look like clean code?
A JSP page should consist of either a mix of markup and Java or
preferably only markup. If it was all Java then you should use
a servlet instead. So I think it makes sense for Eclipse to color
code it as HTML and not as Java.
<% %> are indeed considered primitive / old fashioned / bad style.
There are several techniques that can be used to avoid that
mix and get more clean code. Most important should be
JSTL and bean classes.
Any good JSP tutorial or book (which likely would be 15+ years old!)
would describe those.
I have written something:
https://www.vajhoej.dk/arne/articles/jeetrick.html
which you may consider useful - or not.
Arne
A JSP page should consist of either a mix of markup and Java orIt looked confusing with the default being html as I saw a class like myjsp.jsp got converted when it compiled to generate something like a myjsp_jsp.java.
preferably only markup. If it was all Java then you should use
a servlet instead. So I think it makes sense for Eclipse to color
code it as HTML and not as Java.
<% %> are indeed considered primitive / old fashioned / bad style.We have a lot of <% %> like the jsp files were written by a Java programmer who just wanted to make the entire jsp files into Java code with the html tags just stuck in between.
There are several techniques that can be used to avoid that
mix and get more clean code. Most important should be
JSTL and bean classes.
<% if (condition) { %>
<tag>value</tag>
<% } %>
I did see the JSTL looks cleaner, though converting everything will take awhile. Trying to sort out what goes in front end, back end if this should be any sort of MVC since it's currently html, jsp, java, javascript all in one file. I did see how tomake a servlet, or tag files, to separate things out. Just trying to clear up what should go where.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 30:09:43 |
Calls: | 6,648 |
Calls today: | 3 |
Files: | 12,193 |
Messages: | 5,328,362 |