• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

when to create class in java?

 
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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???
 
Bartender
Posts: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1558
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79179
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, I think MVC and three-tier architecture are different things.
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may benefit from reading this article.
 
Punit Jain
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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??
 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you..
 
I think she's lovely. It's this tiny ad that called her crazy:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic