views:

164

answers:

5

hi

i have written a java program which currently runs as a desktop app,

it is returning all results accurately as required in the console. I am now faced by a challenge to convert this application to a web application (JSP).

Currently, the code for my projects is in user/workspace (as i am using eclipse)

and my tomcat has been installed at c:/server/tomcat..

I am basically a .net developer and know peanuts about java web development. Can someone please guide me as to how i can convert my current project into a web application?

how do i include the project in user/workspace in the jsp file? havent done it before so its as confusing as hell.

it will be most helpful if you can point me in the right directon, or even provide some links so that I can use thm as a pointer

Many Thanks in Advance.

+1  A: 

I recommend reading a JSP tutorial. It isn't that hard. To get you started quickly, these are the required steps:

  • Create a web application. It is better to use a IDE like Eclipse or Netbeans to do so. A quick and dirty solution is to create the jsp under webapps/ROOT in Tomcat
  • The jsp is like an html file with some special tags that allow it to run java code.

This is how you include classes or packages:

<%@ page language="java" import="mypackage.MyClass" %>

You put your Java code inside a <% %>. You can practically put all your java code there.

  • Replace System.out.println in your console app with the following tag:

    <%= mymessage %>

The mymessage will be directly printed in the html source.

  • Finally start Tomcat and point to your jsp file.

For a beginner, I would recommend to start from a tutorial for Eclipse or Netbeans.

kgiannakakis
Actually, you should not import classes in JSP as said here (you can certainly use this tactic to prototype but don't get use to it!). The main purpose of Jsp is to display the model that is managed by a Servlet. In the end, to display this model use JSTL[1] instead.[1] http://java.sun.com/products/jsp/jstl/
Valentin Jacquemin
+1  A: 

The technical part of converting your project into a web project is fairly easy. You can simply create a new static or dynamic web project using eclipse and copy your code into the source directory of that project. Google it and you're there. The next step would probably be to understand how your application is deployed, and how do you configure it. Keep in mind that you switch architecture here. A web application is a client server application that executes in a servlet container which comes with some rules unless all you need to do is print some text into a browser.

I suggest that you start reading here: http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets.html#99975 http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/JSPIntro.html

The first link refers to Servlets, the reason I point you to Servlets first is that JSPs are actually servlets, and servlets are easier to begin with.

Hope this helps.

Shai
+2  A: 

I suggest not to use the JSP technology anymore unless you have to (-> customer demands it).

Instead, get GWT or Grails. Both come with tools to setup a project in Eclipse from scratch that compiles and can be run with the press of a button. Also, both technologies are much more advanced than JSP and you'll find them much more simple to understand as a .Net developer.

Aaron Digulla
Right ;) But Grails uses GORM by default. Switching the persistence layer is a problem yet. I he should have a look at Spring WebMVC! It's pretty staight forward for an existing application. JSF is overkill (and broken by design). GWT rely on Javascript. Tapestry may be also an alternative.
Martin K.
Thank you all for your wonderful guidance, all ur advice has given me important insight into java and web programming using java. However, as my application works with a lot of jquery and Javascript, GWT has fit into the picture well for this situation.Thanks once again for all your help.Best Regards
Mponnada
+2  A: 

If all you want do do is to display the output in a html page, the simplest ways is still to use jsp.

You can do as mentioned in kgiannakakis answer

If your class already returns a string with a nice output, everything you need do this.

<%
MyClass = new MyClass();

%>

<pre>  <%-- pure html, preformatted --%>
<%= myClass.formattedStuff();    %>
</pre>

No fancy html formatting, though. Just a text dump.

You can use for-loops and if-clauses and what not, as everything between <% %> is normal java.

If you need more functionality, You should probably not bother with jsp at all. (And absolutely not at all with JSTL, which would be a total waste of time if you are not intending to start a career writing web apps for big enterprises.

Perhaps GWT :-) Its almost java.

KarlP
+1  A: 

Try this, http://simple.souther.us it has all to get you started.

Adeel Ansari