Mponnada
Mponnada

Reputation: 283

Java to JSP. How to?

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.

Upvotes: 2

Views: 1378

Answers (5)

Adeel Ansari
Adeel Ansari

Reputation: 39907

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

Upvotes: 2

KarlP
KarlP

Reputation: 5191

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.

Upvotes: 3

Aaron Digulla
Aaron Digulla

Reputation: 328790

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.

Upvotes: 3

Shai
Shai

Reputation: 123

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.

Upvotes: 2

kgiannakakis
kgiannakakis

Reputation: 104198

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:

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.

Upvotes: 2

Related Questions