Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39654 > unrolled thread
| Started by | "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> |
|---|---|
| First post | 2020-12-29 07:27 -0800 |
| Last post | 2020-12-29 22:43 -0500 |
| Articles | 4 — 2 participants |
Back to article view | Back to comp.lang.java.programmer
What's the deal with JSP? "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2020-12-29 07:27 -0800
Re: What's the deal with JSP? Arne Vajhøj <arne@vajhoej.dk> - 2020-12-29 13:48 -0500
Re: What's the deal with JSP? "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> - 2020-12-29 13:59 -0800
Re: What's the deal with JSP? Arne Vajhøj <arne@vajhoej.dk> - 2020-12-29 22:43 -0500
| From | "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> |
|---|---|
| Date | 2020-12-29 07:27 -0800 |
| Subject | What's the deal with JSP? |
| Message-ID | <3fb97b37-b0e7-48a3-a2b3-c4d1a828d6dbn@googlegroups.com> |
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?
[toc] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2020-12-29 13:48 -0500 |
| Message-ID | <rsftmh$8j4$1@gioia.aioe.org> |
| In reply to | #39654 |
On 12/29/2020 10:27 AM, e.d.pro...@gmail.com wrote: > 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
[toc] | [prev] | [next] | [standalone]
| From | "e.d.pro...@gmail.com" <e.d.programmer@gmail.com> |
|---|---|
| Date | 2020-12-29 13:59 -0800 |
| Message-ID | <9d058e34-6f36-4322-a639-67de2b842012n@googlegroups.com> |
| In reply to | #39655 |
> 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.
>
It 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.
> <% %> 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.
>
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.
<% 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 to make a servlet, or tag files, to separate things out. Just trying to clear up what should go where.
> 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
This does look very useful, thanks!
[toc] | [prev] | [next] | [standalone]
| From | Arne Vajhøj <arne@vajhoej.dk> |
|---|---|
| Date | 2020-12-29 22:43 -0500 |
| Message-ID | <rsgt1f$1gtk$1@gioia.aioe.org> |
| In reply to | #39656 |
On 12/29/2020 4:59 PM, e.d.pro...@gmail.com wrote:
>> 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.
>>
> It 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.
From an application perspective you should just look at
the JSP and what it does - how it does it should not
matter unless you are developing a web container. (*)
But yes typical the .jsp get converted into a .java that get compiled
into a .class that get loaded and JIT compiled to native code by the
JVM.
*) Actually looking at the generated .java can occasionally be useful
for troubleshooting certain compile errors.
>> <% %> 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.
>>
> 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.
> <% if (condition) { %>
> <tag>value</tag>
> <% } %>
It is bad style.
It was also common style 20 years ago.
:-)
> 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 to make a servlet, or tag files, to separate things out. Just trying to clear up what should go where.
Some best practices, JSTL etc. improved JSP a lot in the early 00'es.
Of course with JSF 2.0 in 2009 and facelets becoming default view
technology, then JSP was no longer "it".
Arne
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web