简体   繁体   English

Spark-Java 框架、Jetty 和 JSP 文件

[英]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.请放轻松,我对整个 Web 开发还很陌生,而且我有点困惑。

I have the Spark framework installed from Maven, which has Jetty as its underlying web/application server, correct?我从 Maven 安装了 Spark 框架,该框架将 Jetty 作为其底层 Web/应用程序服务器,对吗? Jetty is embedded in the Spark jar so I can't/shouldn't mess with it. Jetty 嵌入在 Spark jar 中,所以我不能/不应该弄乱它。 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.我读到 Spark 的嵌入式 Jetty 应该支持 JSP 文件的呈现,但是我的浏览器实际上将我的 JSP 页面解释为文本文档。 How do I tell Spark/Jetty that it needs to interpret and serve these pages as opposed to just serving them as is?我如何告诉 Spark/Jetty 它需要解释和提供这些页面,而不是按原样提供它们?

I'm using Spark 2.5 and the velocity template engine.我正在使用 Spark 2.5 和速度模板引擎。

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.我只是在 Jetty 运行时将路径输入到我的浏览器中,而不是设置到我的 JSP 文件的路径。

I've tested several different minimal JSP files this way.我已经用这种方式测试了几个不同的最小 JSP 文件。

I added a route in Spark to my JSP file and lo and behold, now it attempts to render the file!我在 Spark 中添加了一个路由到我的 JSP 文件,瞧,现在它尝试渲染文件! I suppose Spark has to handle the interpretation of the string passed to it and Jetty simply serves the content?我想 Spark 必须处理传递给它的字符串的解释,而 Jetty 只是提供内容? 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.编辑:很抱歉让这件事从死里复活,但它还没有答案,所以要求清晰……我在我的程序中使用 spark 框架添加了路由,并使用了 render() 函数spark 让 Jetty 呈现 JSP 文件。 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.我之前一直将 JSP 文件的路径作为静态文件输入,因此 Jetty 没有解释文件服务器端的内容(就像您对 JSP 所做的那样),而是尝试将文件本身交给客户端的浏览器. Rookie mistake!菜鸟失误!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM