Skip to content
Advertisement

Spark-Java framework, Jetty and JSP files

Go easy please, I’m rather new to the whole web development thing and I’m a little perplexed.

I have the Spark framework installed from Maven, which has Jetty as its underlying web/application server, correct? Jetty is embedded in the Spark jar so I can’t/shouldn’t mess with it. Is that correct so far?

I read that Spark’s embedded Jetty should support rendering of JSP files, however my browser is literally interpreting my JSP pages as text documents. How do I tell Spark/Jetty that it needs to interpret and serve these pages as opposed to just serving them as is?

I’m using Spark 2.5 and the velocity template engine.

Very minimal code so far. Rather than setting up a route to my JSP file I’ve just been typing the path into my browser while Jetty is running.

I’ve tested several different minimal JSP files this way.

Advertisement

Answer

I added a route in Spark to my JSP file and lo and behold, now it attempts to render the file! I suppose Spark has to handle the interpretation of the string passed to it and Jetty simply serves the content? Beats me! It works!

EDIT: Sorry to bring this back from the dead, but it doesn’t have an answer yet and clarity was asked for so…. I added the route using the spark framework in my program, and used the render() function of spark to have Jetty render the JSP file. I had previously been entering the path of the JSP file as a static file, and so Jetty was not interpreting the contents of the file server side (as you would do with JSP) but instead trying to hand the file itself over to the client’s browser. Rookie mistake!

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement