File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

when to create class in java?

 
Punit Jain
Ranch Hand
Posts: 1012
2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i have a question, i have created a program for employee records i used a simple employee class for that, which have setters and getters, and one java class is for database code, and one is the main class, now my assignment is to create a registration form using servlets, and i want to write a good code, but i m confused do i create simple class file also for this??
simple class i mean with all the form fields with their getters and setters???
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

First things first : you'll get much more help if you put this query in servlet forum.

Apart from that, if you really want to write a good code, I would not recommend writing a servlet which looks like a bean (i.e. all private fields, getters and setters et-cetera).

Much better would be to use MVC pattern. It looks like you've got your code ready for desktop environment (employee and registration class etc.)

All you'll have to do is:
1) Create a 'view' (which can be as simple as HTML page, or a complex JSP or anything from which you can call servlet)
2) Create a 'controller' (here, it would be servlet - which will accept the requests from view; not necessarily that you'll have only one controller throughout your code)
3) Create a 'model' - which is your existing code. Controller, depending on the nature of requests, will invoke respective methods on corresponding objects. Of course, you can write all your business logic in servlet, but then, it would not be good code

If you don't know anything about servlet, MVC etc. then I'll suggest to go through some basic book like head first servlet & jsp.

I hope this helps.
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

First things first : you'll get much more help if you put this query in servlet forum


i dont know ho do i move my post fro one forum to another.
and yes i got it what you want to say, you mean for registration i should use an mvc architecture, but what if i need to do this using 3tier architecture.??
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Punit Jain wrote:i dont know ho do i move my post fro one forum to another.

I'm not sure about this. I guess only admins/moderators (Roberto Perillo, Rob Spoor, Stephan van Hulst) can do this.
Punit Jain wrote:and yes i got it what you want to say, you mean for registration i should use an mvc architecture, but what if i need to do this using 3tier architecture.??

I'm not a JEE guru, but I guess MVC itself is 3 tier architecture. Anyways, if you wan to further extend this, you can have one more layer - database. All you'll have to do is make a call to model, and your model (business logic) would do the rest - i.e. modifying database etc.

I hope this helps.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I think MVC and three-tier architecture are different things.
 
Wendy Gibbons
Bartender
Posts: 1107
Eclipse IDE Oracle VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To answer your question, yes you will need a servlet (control) for the login screen.
Is this logging into the app?
as you will then need to call out to another database class (model), which will test if the credentials match a user on the database. returning to your servlet, which will then control the next page (view) the user goes to.

I like a servlet for each page or form.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64192
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may benefit from reading this article.
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this logging into the app?


ya definitely i will nedd a mvc pattern for login screen, but don't know why mvc..
but i have only registration page, and that i want to code but with a good code/pattern.



No, I think MVC and three-tier architecture are different things.

yes i think so that both are different...
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

You may benefit from reading this article


i read this article, really nice, i never thought that this can also be happen when i make such type of applications, but i have a question,
suppose i have a page in which i have code to delete as well as to display, as in your example in the article, but in the code i am checking weather the request is for delete or display, so how this problem comes, although i m checking for post??



one more thing, i want to know how can i check for "Double Submit problem" i mean can i test this, weather my data is double submitted or not, i m still confused...

and as your article says, for my registration page i should use mvc/model2??
 
Victor M. Pereira
Ranch Hand
Posts: 50
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well in any case it's just a normal class extending HttpServlet.

If you want to do the extra mile.

1) An HTML page with the login form.
2) You can have a servlet (Controller) that process the data and calls your database class to persist.
3) A JSP Page that shows all the rows or just shows confirmation of the persistance.

I'll also recomend you the head first servlet and jsp book.

P.D. If you want good code don't write scriptlets (i.e. the <% %> tag) in your jsp
 
Punit Jain
Ranch Hand
Posts: 1012
2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you..
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic