7

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 to 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.

uriDium
  • 13,110
  • 20
  • 78
  • 138

8 Answers8

5

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.

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • 1
    +1, agree. The problem I find is most tutorials assume you WANT to use everything and the kitchen sink, so they write contrived and overcomplicated examples of simple things using very heavy EE stuff. I'd like to see a tutorial that covers a web page in Java with the absolute *minimum* of fuss and bother, but they're hard to find. – FrustratedWithFormsDesigner Jun 29 '10 at 14:40
  • Probably deep misunderstanding to be honest. I never really got the EE architecture that well. I did just a bit. For the most part I did SE stuff in a server environment. – uriDium Jun 29 '10 at 14:42
  • @uriDium: No problem. What I don't get is that part that makes you think you can't do "simple things" with Java EE. As I wrote, just write a `Servlet`, that's all you need. – Pascal Thivent Jun 29 '10 at 14:45
  • @ Pascal, my ignorance once again. But as far as I knew I had to have an application server when I started using Java EE. I thought Java EE had all the message queuing and inter-process communication. So I thought it would be better to just avoid the whole thing. If you have used ASP.Net I am almost looking for a simple webpage with a code-behind. I have even considered using mono and doing just that. Thanks for your feedback. – uriDium Jun 29 '10 at 14:50
  • @uriDium: You seem to be using *Java EE* to refer to the *runtime environment* (a Java EE app server) while I consider *Java EE* to be the *API*, hence the confusion. So, as I wrote in another comment, a servlet container (i.e. not a full Java EE server) will be fine if you only need the Servlet API. – Pascal Thivent Jun 29 '10 at 15:49
4
  1. You need Tomcat (or jetty, or any servlet container - jetty has an embeddable version btw)
  2. You need a .jsp file and optionally an HttpServlet

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.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
  • 1
    The OP doesn't **need** Tomcat or whatever, he **could** use Tomcat or Jetty or JBoss or GlassFish or WebLogic, etc. The runtime environment doesn't really matter, the point is that the OP can use a small part of something big. – Pascal Thivent Jun 29 '10 at 14:39
  • @ Pascal. But I don't want to download Java EE if I can avoid it. And I especially would prefer to avoid the pain of JBoss if or some other application server if I can avoid it. – uriDium Jun 29 '10 at 14:45
  • 1
    @uriDium: That's not my point. My point is that even if your company is running all its project on a corporate full Java EE server, you can use a tiny part of Java EE. Now, if you have the choice, Tomcat or Jetty will be fine for a single Servlet application. – Pascal Thivent Jun 29 '10 at 14:50
2

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.

irreputable
  • 44,725
  • 9
  • 65
  • 93
0

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.

Community
  • 1
  • 1
Janus Troelsen
  • 20,267
  • 14
  • 135
  • 196
0

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.

ryangavin
  • 424
  • 2
  • 6
  • 1
    Recommending PHP in a Java question is like throwing Natrium (*aka Sodium*) to water. – Esko Jun 29 '10 at 14:33
  • @Esko: The OP *did* say he was open to using something other than Java if it would be even easier. In fact, if the OP is a strictly Java-only guy, this might be a good chance to dabble in some other technology, though it will take longer to get up and running, with learning curves of new tech and such... – FrustratedWithFormsDesigner Jun 29 '10 at 14:37
  • Definitely open to anything at this point. I was considering dabbling in Ruby On Rails. Only reason I am opting for Java at this point is because I have the most experience with it. – uriDium Jun 29 '10 at 14:44
  • @uriDium: Though if you have spare time after the Java implementation, try porting to PHP, just to see what it's like. You'll learn something new. :) – FrustratedWithFormsDesigner Jun 29 '10 at 14:49
  • @Frustrated: I'm not saying it isn't a good recommendation, just that based on my experience PHP is seen as the antichrist of scripting languages among Java devs which may cause heated verbal battles very easily. Thankfully that didn't happen here, I was worried this would end up like 99% of PHP discussions I've had lately. – Esko Jun 30 '10 at 06:06
  • I dev with both Java and PHP depending on the project. Each has its uses, pros, and cons. – ryangavin Jun 30 '10 at 12:44
0

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

naikus
  • 24,302
  • 4
  • 42
  • 43
0

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.

Paul Sanwald
  • 10,899
  • 6
  • 44
  • 59
-1

I would reccomend Sinatra it is a very light-weight ruby web framework.

Maz
  • 3,375
  • 1
  • 22
  • 27