JDK 1.8 Power not Available for the Web, Yes or No?

J

Jan Burse

Dear All,

I made a small experiment recently with JSP
and got the impression that the full power
of the JDK 1.8 is currently not available for
the web.

What I tried was very simple, I included
a closure in a JSP text. But the JSP system
refused to allow the <% %> tags inside the
closure.

My code looked as follows:

<%
do some computation;

do some computation that

needs a continuation (new some base class() {

the computation of the continuation goes here

%>here goes some HTML code of the continuation<%

more computation of the continuation goes here
}

do some other computation
%>

The problem I were facing were:

- Tomcat refused an inner class without <% %>,
in case I was addressing out in the inner class.
It said that out is not final.

- My IDE refused an inner class with <% %>
all together, it marked it as an error.

So it seems that all this fuzz about closures
doesn't carry over to the web. Which makes me
currious about some of the web frameworks from
some of the functional languages camps.

But I might also be totally wrong, i.e. that
I don't have the right tomcat version etc..
and that the web can profit from JDK 1.8. But
I didn't find much through googling so far.

Comments welcome
 
A

Arne Vajhøj

I made a small experiment recently with JSP
and got the impression that the full power
of the JDK 1.8 is currently not available for
the web.
So it seems that all this fuzz about closures
doesn't carry over to the web. Which makes me
currious about some of the web frameworks from
some of the functional languages camps.

But I might also be totally wrong, i.e. that
I don't have the right tomcat version etc..
and that the web can profit from JDK 1.8. But
I didn't find much through googling so far.

A given version of Tomcat uses a given version of a
Java compiler.

If your version of Tomcat does not use a Java compiler
that supports Java 1.8 then it is obviously a no go.

I am sure that eventually Tomcat will ship with a 1.8
compiler.

If you can't wait then use Google to find the description
of how to change the version of ECJ that Tomcat uses (all
recent Tomcat versions uses the Eclipse compiler not the
regular SUN/Oracle JDK compiler). An 1.8 compatible ECJ do
exist.

Arne
 
J

Joerg Meier

I made a small experiment recently with JSP
and got the impression that the full power
of the JDK 1.8 is currently not available for
the web.
What I tried was very simple, I included
a closure in a JSP text. But the JSP system
refused to allow the <% %> tags inside the
closure.

In addition to what Arne said, <% %> is hardly the only version of Java
"for the Web", in fact, as far as I understand, it's a rather archaic,
outdated and heavily discouraged nieche of Java Web.

Liebe Gruesse,
Joerg
 
M

MilkoB

A given version of Tomcat uses a given version of a
Java compiler.

If your version of Tomcat does not use a Java compiler
that supports Java 1.8 then it is obviously a no go.

I am sure that eventually Tomcat will ship with a 1.8
compiler.

If you can't wait then use Google to find the description
of how to change the version of ECJ that Tomcat uses (all
recent Tomcat versions uses the Eclipse compiler not the
regular SUN/Oracle JDK compiler). An 1.8 compatible ECJ do
exist.

Arne


The original poster needs to install Tomcat 8 and configure it to use
JDK 1.8/J2EE 7.

Then, open the Tomcat 8's $CATALINA_HOME/conf/web.xml in an editor, find
the following section at around line 230 in the web.xml, add the lines
between the two comments below

<servlet>
<servlet-name>jsp</servlet-name>

<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
<init-param>
<param-name>fork</param-name>
<param-value>false</param-value>
</init-param>
<init-param>
<param-name>xpoweredBy</param-name>
<param-value>false</param-value>
</init-param>
<load-on-startup>3</load-on-startup>
<!-- Add the following new lines exactly here -->
<init-param>
<param-name>compilerSourceVM</param-name>
<param-value>1.8</param-value>
</init-param>
<init-param>
<param-name>compilerTargetVM</param-name>
<param-value>1.8</param-value>
</init-param>
<init-param>
<param-name>compiler</param-name>
<param-value>modern</param-value>
</init-param>
<!-- End of newly added lines -->
</servlet>

and restart Tomcat. That should make Tomcat 8 start using javac
from the Oracle/Sun JDK 8 instead of built-in ECJ.

Hope this helps,

MB
 
J

Jan Burse

Jan said:
Comments welcome

Assume I configure tomcat to use JDK 1.8, and
it will run with JDK 1.8, there are still
problems with continuation.

If I remember well some weeks ago, I tryed
JDK 1.8 for tomcat, and it didn't work. And
it seems that tomcat primarily goes for JDK 1.7,
see also:

Does Tomcat 8 support Java 8?
http://stackoverflow.com/questions/18208805/does-tomcat-8-support-java-8

But the issue is not whether I can plug-in
a JDK 1.7 or JDK 1.8 into tomcat. The issue
is whether JSP spec supports inner classes
to a certain degree, so that some java features
can be used.

I don't know whether in tomcat 8 they changed
the variable out to final, if this is at at
all possible. So that I would be able to use
it in an inner class.

When I can use out in an inner class, then
I will probably also be able to use it in the
JDK 1.8 lambda notation.

Inner classes are already a feature from the
beginning of JDK 1.1. But I never checked how
their support in JSP is. One finds the following
article about inner classes and JSP:

JSP: How to Declare Methods and Inner Class in JSP

http://www.snippetit.com/2009/05/jsp-how-to-declare-methods-and-inner-class-in-jsp/

But the example above doesn't show the case of an
inner annonymous class which is local to a method.
I don't know whether local classes were also already
introduced with JDK 1.1. But according to some
sources the local classes came with nested classes
in JDK 1.1 together with a greater application area
for the final modifier:

In Java 1.0, only fields, methods, and classes can be declared
final. The addition of local classes in Java 1.1 has required a
liberalization in the use of the final modifier. It can now be applied
to local variables, method parameters, and even the exception parameter
of a catch statement. The meaning of the final modifier remains the same
in these new uses: once the local variable or parameter has been
assigned a value, that value cannot be changed.

But I really feel ashamed that I never checked before
whether JSP can use local classes. My testing so
far shows that this JDK 1.1 doesn't work, and subsequently
I guess JDK 1.8 lambdas will also not work. Except
if there isn't only a new tomcat 8, but also a new
JSP spec.

It is really driving me towards the functional
programming camp, and trying some of the fancy
functional web solutions. Including some Scala
web frameworks. Since I have a couple of programming
cases that could profit from JSP continuations.

Bye
 
J

Jan Burse

Jan said:
In Java 1.0, only fields, methods, and classes can be declared
final. The addition of local classes in Java 1.1 has required a
liberalization in the use of the final modifier. It can now be applied
to local variables, method parameters, and even the exception parameter
of a catch statement. The meaning of the final modifier remains the same
in these new uses: once the local variable or parameter has been
assigned a value, that value cannot be changed.

But I really feel ashamed that I never checked before
whether JSP can use local classes. My testing so
far shows that this JDK 1.1 doesn't work, and subsequently
I guess JDK 1.8 lambdas will also not work. Except
if there isn't only a new tomcat 8, but also a new
JSP spec.

It could be that continuations would break some
of the assumptions of JSP. For example it could
be that JSP assumes that out is only served by
one thread as long as the servlet is alive. But
I am not sure.

With continuations I could easily let the servlet
do some concurrent work. If the method that uses
the continuation spawns threads. On the other I
can also pick out manually and give it to threads.
So that the problem is not tied to inner classes
per se.


BTW: Quite a number of Scala based frameworks:

What Scala web-frameworks are available?
http://stackoverflow.com/questions/1488412/what-scala-web-frameworks-are-available
 
J

Jan Burse

Joerg said:
In addition to what Arne said, <% %> is hardly the only version of Java
"for the Web", in fact, as far as I understand, it's a rather archaic,
outdated and heavily discouraged nieche of Java Web.

Liebe Gruesse,
Joerg

Well then here is the bonus question for those
who don't like the <% %> or directly using the
out variable in the JSP. Is there some taglib etc..
that works with continuations?

http://stackoverflow.com/questions/3177733/how-to-avoid-java-code-in-jsp-files

My guess: Its even more difficult to make taglibs
work with local classes, than it is already with
<% %> and out. The bets are open.

Bye
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top