Can I avoid Java EE to create a light-weight web page?
Everything I download seems hellbent on using all of Java EE. I need to build a single page to handle requests to it and do a tiny bit of processing based on parameters. This is to hook into another framework that will routinely call this URL.
I want a quick and easy way t开发者_如何学编程o create a page with some processing. Is there an easy way to do this using Java? I am using Java because I am comfortable with Java. I used SE for years and did some work in EE but I don't want all the stuff that comes with EE.
Should I maybe just avoid Java altogether and use something else. This needs to be deployed in a linux environment.
I used SE for years and did some work in EE but I don't want all the stuff that comes with EE.
Then just use a Servlet and that's all. Nothing, I repeat NOTHING, forces you to use "all that stuff" and your question is either a free rant or shows some deep misunderstanding.
- You need Tomcat (or jetty, or any servlet container - jetty has an embeddable version btw)
- You need a
.jsp
file and optionally anHttpServlet
Generally, it's not a good practice to put any processing code in a JSP, but if it is really simple and won't be extended, simply put the logic there - it is translated to a Servlet anyway.
yes, all the servlet based solutions are quite chubby.
jetty is all right, but the download is 20MB. that is ridiculous.
currently, the best choice is probably com.sun.net.httpserver
which is bundled in JDK 6. you can easily implement your service.
It sounds like you could use PHP to do your processing. Call the page and POST the parameters to it, compute, and return the result.
If you are not very particular about using java and are willing to experiment, you should look at nodejs. It runs on V8 javascript engine and runs on linux. There are a couple of fraemworks for nodejs for web apps:
Expressjs and spludo
as mentioned, you can do this very simply with jetty and a servlet, you don't even need a JSP if you just need a URL that does some processing based on request parameters and returns a response.
For development, it's really easy to create a dynamic web project in eclipse, just follow the steps in this article.
That said, I don't think java is a great choice for really lightweight stuff. PHP is probably the easiest thing to use if you just want to get it working yesterday.
You can use Java with FastCGI. This is very flexible, but also a bit low-level for most Java programmers.
If you aren't afraid of servlets (they are only a very small part of Java EE!), I can recommend JAX-RS, it is quite easy to get started with. If you client-side is JavaScript based, you can avoid using JSP (which I would recommend you to avoid).
For example, see backbone-jax-cellar. The Java source is here. For a Java app, this is light-weight. He is rolling his own DAO, but that's the price you pay for using Java and SQL and no dependencies (other than JDBC). The code is reminiscent of object-oriented PHP if you ask me. The point is, that if you have a JavaScript client, you don't need template rendering or all that cruft and a REST interface should be enough.
If you are afraid of the heavy build systems too, I made an example REST Todo app backend (which uses an existing frontend) that only requires a POSIX system, the JDK and sqlite3, and gets its own other dependencies (including webserver). I did not use a DAO. The repository front page has a README.
Another possibility is the Play Framework which does not use Java EE. It is rather heavy-weight, though. Full featured though. You would definitely need to use an IDE for this, you don't need that for developing JAX-RS/FastCGI apps.
I would reccomend Sinatra it is a very light-weight ruby web framework.
精彩评论