6

I am new in programming and this question may really be stupid but I still want to ask because I don't know what practices are possible and what are not. You see, right now I am studying basic J2EE. Our assignment is to make a web-based application using JSP and servlets. One of my problems is doing the forms.

I know that HTML is the best practice in making the forms in JSP because almost all people are using it(based on the examples on the books/internet). But Java also have its own forms which is the Swing, AWT and it all worked by using the events. If i don't want to use HTML, can I use Java's Swing/AWT or is it for the desktop applications only? Aside from what I've mentioned, what else can I use?

3
  • You can't use Swing component on a JSP page? Commented Mar 5, 2011 at 8:07
  • 1
    @Alpine "You can't use Swing component on a JSP page?" Is that a question? Assuming it is, then look to JApplet. @newbie - if you can avoid embedding applets in a web app., do so. Applets are a PITA to develop and deploy, and most users prefer pure HTML (or dynamic HTML, using JavaScript) to applets. "I know that HTML is the best practice in making the forms in JSP because almost all people are using it(based on the examples on the books/internet)" Examples on the internet are not intended to be finely crafted apps. they are simply intended to show the technology in its simplest form. Commented Mar 5, 2011 at 8:19
  • 1
    ..and servlets are preferable to JSP. Any example based around JSP is suspect to start with. As to output forms, either technology can generate HTML (3.2, 4.01, 5 etc.) XHTML, ..or whatever you program them to deliver. Commented Mar 5, 2011 at 8:22

6 Answers 6

4

What you are talking about is called Rich Internet Applications RIA. These are web applications that make your web pages look like desktop applications. You can achieve this with Grails and Flex, GWT and JavaFX. There is a number of very interesting and great environments you can use like Vaadin, Open Laszlo, based on GWT. GWT and the frameworks based on it generate JavaScript and produce separate output for every browser environment.

These are the tools for the future. I do not really understand why these technologies are not mainstream yet.

Here is a list of the various RIAs frameworks available. Expect to welcome newcomers in SourceForge in the near future.

Sign up to request clarification or add additional context in comments.

Comments

3

But Java also have its own forms which is the JSwing, Swing, AWT and it all worked by using the events.

Yes java has many Components in Swing and AWT.
And both Swing and AWT Components support Event Handling.
But I never have heard of JSwing.

If I don't want to use HTML, can I use Java's JSwing/Swing/AWT or is it for the desktop applications only?

Swing and AWT are for the desktop application only.
But as Orbit said

In Appletz? – Orbit

You can definetly use Swing components on an applet and then embed the applet on your JSP page.

I know that HTML is the best practice in making the forms in JSP

Using HTML will be a lot easier than using Applet to make a form

As Andrew said

Applets are a PITA to develop and deploy, and most users prefer pure HTML (or dynamic HTML, using JavaScript) to applets.

1 Comment

I call Java Swing as JSwing heheheh.. sorry about that
2

You can try out Wicket - seems like transfer your desktop expirence to web

Comments

2

Perhaps you need to think about what is running where, and how those programs communicate. When you develop a web application, you are co-ordinating a conversation between (at least) two separate machines.

  1. On one side, you are running a web server, that serves up static content (simple files that are just sent out with no changes) and dynamic content (essentially files that are constructed only when needed, and that will change according to their situation - for instance a welcome page that displays the user's name). Plain HTML is static content, JSP and servlets provide dynamic content.

  2. On the other side, you are running a browser. The browser can display static content, run javascript programs built into those pages, and embed specific types of applications. Examples of embedded applications are Flash and Applets.

So you can be clear, JSP and Servlets are NOT running on the client machine, they just deliver different content for the browser to display. A J2EE program is not delivered to the client, it just sits on the server carrying out one side of the conversation with the browser carrying out the other side.

A web form is just a lump of HTML that tells the browser to display text fields, buttons and other controls. The browser knows all about these things, and you don't need to write a program to tell it what to do to display a form and send the content back to the server. A simple form doesn't need to be dynamic - you're asking the same questions every time - so you can write it in pure html.

When the user submits the form, the data is transmitted to the server and you will need to write a program to receive that data and do something with it. That is the role of the servlet, which can receive data and respond - with another web page, probably using JSP to display dynamic content (ie. the answer to the form submission).

If that all sounds complicated, it certainly can be. There are various frameworks (Wicket, Struts and so on) that try to make it easier to develop web applications by hiding some of the details of the conversation, and carrying out common tasks automatically. However, the underlying mechanism is still the same - content from the server is displayed on the browser, which can send back messages such as form contents, or requests for different pages. Understanding the basic mechanism allows you to make informed choices about how you can do more powerful things.

Embedded applications allow you to run more complex software on the client - so you can display animations or custom controls. However, the software is ONLY running on the client, and still needs to communicate data back to the server. The server still needs to be running it's own software to receive that data and do something with it. As such, embedded applications don't make your job any easier, but do allow you more control over how things work on the client. However, a modern web browser gives you a lot of control over how forms are displayed and handled, so you need a good reason to ditch that and use something like Flash or an applet.

Comments

2

For websites, always use HTML (and Javascript, for things like input corrections, alerts and such). The less you use Java and Flash, the better. Keep in mind that websites must be fast and efficient, users don't want to wait minutes until the Java applet loads.

Comments

1

I would recommend you to do in HTML. Because HTML can do wonnders and you can split your web apps sematically using HTML. And i recommend you to use Wicket(its an framework), where all are been splited. That is, web designing can be done separately using HTML, presentation can be done via CSS and the event handling all can be done via JAVA. And wicket takes care of all these connections too. So have a look on Wicket. And hope it helps you.!

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.