• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Need Advice in my Project Design

 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody:
I want to do a project using these following things
1)Servlets & JSP
2)Tomcat3.1
3)Ms-access
I am actuually doin a project Know as "Course Test Manager " . I am doin this for my Department in my school . If the profesors approive it they might use it in the School. so i need to finish my project by dec15th. I am new to servlets and JSP . i have only some small programs in these texchnologies. So i am struck in the design.
with my website the professors and the students can login the system . login info is stored in database (userName , passWord, Role) According to the role he servlet should redirect to the professor menu option screen (HTML) or student (select test option) . This is the first thing i wanna do
the other thing i want to know how should have connection pool class set and in which servlet should i be callin to get the connections. How should i go abt doin my interaction with databse and make it threadsafe . can anyone tell me how to design till this. Once i finsnish this part i will let u know what else i have to do.
If anyone need more info abt this i will be happy to give u the info
Thank you
Siva
[This message has been edited by Sivakumar Jagadeesan (edited November 23, 2000).]
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if more number of user access the data base then go for connection pooling otherwise no need. one more thing what do u want regarding the design can u be specific
------------------
I.K.VISHWANATH
 
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Regarding Access database part, you have to define a ODBC Data source and use this Data Source name in your servlet which making connection to the database. This procedure simple and litte different on WIN NT and WIN 98. Which platform are you using?
regds
maha anna
 
Siva Jagadeesan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Kasi and MahaAnna :
Thank you.
I am using Windows98. I think setting up the Data Source Name and connection to the Database shouldn't be a problem for me .
I am just confused how should i do these things and in which order. Many users will be using the system at the same time , so i got a class ConnectionPool wich will give a avialable connection.
This is my login part of my system:
The user enters the password , the ysstem identifies whether the user is a student or a professor and it redirects them to the approriate html page.
So how should i go abt doin this ?
let me explain the way i have understood these things and how i am planning to do this use case.
There is login Html page which sends the userName and the passWord to the LoginServlet. The LoginServlet uses the DatabaseClass which uses one of the connection from the ConnectionPool and returns the following details of the user
1)userName
2)courses presently takin
3)Role
the LoginServlet creates a UserBean which stores this info and stores the bean in the Session .
Is this a good way to do this stuff.
if it is good way , then where should i place my start ConnectionPool ,whether in the init()of of the LoginServlet or in the DatabaseClass ?
pls let me know.
I am struck , and i have long way to go
thank you
siva
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
- Get the login and password from login.html/login.jsp. (View)
- When the user submits the login form call LoginServlet. (Model)
- Let all your servlets share a common connection pool, which exists in 'ServletContext'.
- The checking,creation, putting the connection pool in ServletContext, all have to be done in init(..) of all the servlets in the web application.
- In other words, each servlet , in its init(..) method will first check if there is a connection pool object exits in ServletContext. If so, it assigns the object to its, private instance variable named 'coonectionPool'. If not it CREATES one and offers to ServletContext. From then on all other servlets just use the common Connection Pool object in ServletContext.
- I assume that your ConnectionPool part is ready with all its functions working properly. (getConnection,freeConnection etc) There is a very good working code from Marty hall's book. I think it is also available in his web site www.coreservlets.com. Please check.
- So this LoginServlet, first should validate the form. Eventhough you might have used the JavaScript at the browser, it is always good idea to make serverside validation again. If there is a mischief user you just directly calls this LoginServlet from Browsers's address bar, by giving the login and password vars, then our appn still should validate the form at the server end also.
- Create a WorkerBean which does validation work. For LoginForm there may be LoginWB. (I just created one WorkerBean for each form)which may have 'logon' and 'password' as member valiables and validateForm() method which just validates if the form came with proper inputs or not.
- The LoginServlet does not do any validation on its own. It creates a WorkerBean with HttpServletRequest and then calls validateForm() on that bean . ( for further good design, the constructor of the WorkerBean should not depend on HttpServletRequest object. It mat take another class which has login and password as mem vars so that in future if this worker bean has to be RE-USED for anoter appln wher the input doesnot come from HttpRequest also, it will be useful. This is the catch made by Thomas ! ) If validation fails, re-route to Login.jsp /unsuccessfulLogin.jsp.
-OR get a connection from ConnectionPool. use this connection and pass this conn obj to UsersBank.validateUser(Connection coon, String login, Sting password) method (just an example).
- Get the boolean result
- if success take next step
-else forward to unsuccessfulLogin.jsp
This is an overall idea about how you should design your appln for scalablity. Also note that if you want to RE-DISPLAy the login and password in unsuccessfulLogin.jsp, then you might have to setAttribute either in request/session scope with a ViewBean/WorkerBean itself so that in the forwarded jsp you can grab the login and password which the user already typed.
I am replying from another machine so I am not able to give links. I try to help next time. Meanwhile please get an idean from what I said, and try to adhere MVC design pattern.
regds
maha anna
[This message has been edited by maha anna (edited November 24, 2000).]
 
Siva Jagadeesan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Maha:
Thank you a lot J
I did as u said and it works fine .
Okay let me explain what I did .
I have class ConnectionPool(which I got from the CoreServlets.com )
Instead of using ServletContext I used a singleton class TestManagerPool
public class TestManagerPool extends ConnectionPool{
private static TestManagerPool pool = null;

//private constructor which calls the constructor of the ConnectionPool class
private TestManagerPool(String driver, String url,
String username, String password,
int initialConnections,
int maxConnections,
boolean waitIfBusy)throws SQLException {
super(driver , url , username , password , initialConnections ,
maxConnections , waitIfBusy);
}

//gets the instance of the TestManagerPool
public static TestManagerPool getInstance()throws SQLException{
return (pool);
}
public static TestManagerPool getInstance(String driver, String url,
String username, String password,
int initialConnections,
int maxConnections,
boolean waitIfBusy)throws SQLException{
pool = new TestManagerPool(driver , url , username , password , initialConnections ,
maxConnections , waitIfBusy);
return(pool);
}
};
When getInstance is called it is gives the instance of the ConnectionPool.
I have another class called DBConnector which connects to the data base

public DBConnector (){
try{
pool = TestManagerPool.getInstance();
if(pool == null){
pool = TestManagerPool.getInstance(driver, url, username, password,
initialConnections, maxConnections, waitIfBusy);
}
}
catch(SQLException sqle){
System.out.println("Error in gettin Pool");
}
}
public synchronized ResultSet executeQuery(String statement){
Statement stmt ;
ResultSet rs = null;
Connection connection ;
try{
connection = pool.getConnection();
stmt = connection.createStatement();
rs = stmt.executeQuery(statement);
pool.free(connection);
}
catch(SQLException sqle){
System.out.println("Error in the Query");
}
return(rs);
}
public synchronized boolean executeUpdate(String statement){
Statement stmt ;
Connection connection ;
try{
connection = pool.getConnection();
stmt = connection.createStatement();
stmt.executeUpdate(statement);
pool.free(connection);
return(true);
}
catch(SQLException sqle){
System.out.println("Error in the Query");
return(false);
}
}

My LoginServlet gets the username and password sets up the LoginWB then it calls the validateForm() . if it fails it sends to unsuccessfullogin.jsp .if it is successful . then it creates the instance of the UserValidation class
public class UserValidation {

private DBConnector connection ;
private String username , password , role;
private boolean valid = false ;
public UserValidation(String name , String pass){
try{
this.username = name ;
this.password = pass;
connection = new DBConnector();
checkValidation();
}
catch(Exception e){
System.out.println("error");
}
}

private void checkValidation(){
String realUserName , realPassword , realRole = "0";
ResultSet rs = connection.executeQuery("SELECT * FROM UserInfo");
try{
while(( valid == false) && (rs.next()) ){
realUserName = rs.getString(1);
realPassword = rs.getString(2);
realRole = rs.getString(3);
if( (username.equalsIgnoreCase(realUserName)) && (password.equals(realPassword)) )
valid = true;
}
}
catch(SQLException e){
System.out.println("ERROR in RESULTSET");
}
if (valid)
role = realRole;

}

public boolean isValid(){
return (valid);
}
public String getUsername(){
return (username);
}
public String getPassword(){
return (password);
}

public String getRole(){
return (role);
}
public static void main(String args[]){
System.out.println("Welcome");
UserValidation user = new UserValidation("nagy" , "1");
if(user.isValid()){
System.out.println("Is Valid \n" + user.getRole());
}
else{
System.out.println("Not Valid \n");
}
}

};
using this class it will check wether the username and password are valid . if valid
the login servlet sets up the UserBean( which has the following properties
1)username
2)role( student / pofessor)
3)String[] courses( the list of courses a student is studying or the professor is teachin that semester)
then it adds to the Session .(this is the part I am not quite clear )
it checks the role and forwards to professorMain.jsp or studentMain.jsp.
So what u think of this design.
Anyway my next case is CREATE TEST.
I am not sure how to design it .
My database structure is like this
Table :
1)UserInfo : UserName(Primary key -PK) , Password , Role
(whether they r student or professor)
2)Course :CourseName(PK) , UserName(The professor who is
teaching that course)
3)Test :TestIndex(PK) , TestNo , CourseName , Date
(Scheduled Date stored as a String )
4)Question :QuestionNo(PK), TestIndex , Type
(Mulptiple/TRuefalse / ShortAnswer) , Question , choice1 ,
choice 2, choice3, choice4 , answer

Do u think it is a good idea to get one question at one time from the professor or all the questions .
I am not sure how can I design it.
Anyway let me first explain the whole project so u can
think abt how we can design it.
The users for the system are
1)Professors and
2)Students
Prpfessor can do these following things
1)Test Management (The professor should have access
only to the courses which he is teaching that particular
semester and only one professor teaches one course at a
particular time )
- Create Test (he can create test only for the
courses he is teaching that semester
-Revise Test (he can modify the questions )(questions
are stored in the QUESTION table and has a field TestIndex
which identify which test it belongs to )
-Delete test (all the questions for that particular test
is also deleted)
-Schedule Test (he can assign a date for a test so that
students can take that test at a particular date)(the date is
stored as a string in the TEST table )
2)User Management
-Student (he can delete , modify , add new
student
-Courses (he can delete , modify , add new
course)

3)Frequency Analyis (it should a give Pie chart or any
chart for the distrubution of the students� marks for a
particular test)
nthese are the things a professor can do
A Student
1)Take test (he can take only the test which is
scheduled and which belongs to the course he is takin this
semester)

Sorry for this long mail
It will be great if u can help me finish this project .
I need to finish this project by dec15th L
So pls help me
Thank you
Siva
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I read your post. From this, I think you are clear about the 'User Requirements' part. But you are caught in between the 'design phase' and 'implementation' phase. I try to give you how we should go about , from 'conception' of the cool project idea upto 'deployment' of the real web application from the experience I gathered. Please read this carefully.

1.1 Get the user requirements and understand them clearly what the user really wants.
1.2 May be just write down in a textfile what are the requirements the users wants. To reduce the communication gap between you and the user, go for prototyping of the 'real system', how will it look finally, and arrage for a meeting with your professor and discuss, if this is what indeed wanted.
1.3 This is what, some architects call as 'iterative phase', which is nothing but go back and forth (erase and draw again ) the screens, after each meeting with the user ( in your case the professor may be). This may take 3 to 4 trails.
1.4 For the above step, if you have a web page design tool, it is well and good. If not, atleaset, take a notebook and FIRST, draw out the screens and the fields, buttons inside the page etc.
This way, you and the professor are thinking in line, what you are going to deliver. It also make ourself clear first. So from start to end draw all the pages and subpages, subsubpages, subsubsubpages etc, everthing the system is going to show to the user.
Now you have the conception of idea, grew into prototype.

2.1 Findout what are the ENTITIES (tables) needed for the system.
2.2 Define the fields, and primary(secondary) keys, unique fields, not null fields , the type and size of the fields etc of each table.
2.3. Now do the normalization. Think in terms of not repeating the same data in different tables. In other words, if there is a set of 'student information' (name,age,address etc) collect and put them in a separate table and whenever you need this student info , for another table , just use the unique key of this student, in the 2nd table. NOT THE WHOLE INFO AGAIN there.
2.4 When you design the tables, keep the prototype papers,(screens) near you, so that, you know whether your database has the information, the prototype needs. This check is definitly needed. If you do not do this check here , latter you may findout, "Oh, I need to change the table design again, code again, test again and everything will be in a chaos!"
So have clear idea about if the database design is in line with the prototype.
Now we have come upto conception - prototype - database Design

There are 2 ways to design. 1. Top-Down 2. Bottom-Up. TopDown is you identify the bigger component ....to smaller component. Bottomup is smaller component .... to bigger one. Depending upon the need, we should go for one of these. Since you are the ONLY person who is going to do everything(design,development,testing) you go for Top-Down desin.
3.1 Findout what are the DIFFERENT Servlets,Classes you can identify which can have their own functionality separated (almost ) from others. Now you identified the 'LoginServlet' isn't? This has its own work of just getting the LoginInfo and routing to success/failed pages. So stick to that. Let the LoginServlet do that related work alone as its name says. Simillarly TRY to identify other Servlets /classes which can have their own work. This is a broder view of the System. Write down all the Component Names (Servlets/classes).
3.2 Now , within each Class, try to identify the methodNames and member vars they may need. Once again we may change these method signatutes slighlty, when we really implement (code) these methods. But that's ok. But we should do this rough design atleast first. Also note that, when we define the members of one class we may identify another broder component need to be defined. It is ok. Just add to the above list of components.
3.3 Now, while defining the members of the class, try to talk with other component's methods. Now you have some idea about how your bigger modules make use of other's methods for their need.
For example now, you may define a ServletUtilities class which has static methods of all kinds, and other Components may make use of them. You need not go into inner details of each methods.
This is where some people use UML diagrams (especially the class-diagrams). It depends. If you don't know uml it is ok. Even I don't. I just used the class diagrams alone. Since your system is not so big or complex, just write down in your textfile/notebook itself.

4.1 Now try to code/test each broder component seperately.
One thing you have to remember is stick to model-view-control design. Try to minimize the code in Servlets. They are just controlers. No SQL CODE, NO HTML CODE in servlets, NO FORM VALIDATION CODE in servlets. Write separate classes for those work. Let the servlets just call those classes's methods.
Another point is DO NOT write HUGE CODE inside one method. Try to minimize the no. of lines of code within one page for each method, so that you should view the whole code in one page. Try to split into smaller logical components (also helps in code reuse).
First get to work!. You can always do the form validation (javascript/server-side-validationpart latter. First get the functionality done with VALID USER inputs from the html/jsp forms.
This is the stage you should worry about how you want to implement the function etc. Do you get this point? It is ok, if you think about how am I going to do all this thread-safe, the connection pool part etc. But not too much during the design phase.
This is the practice I use and found useful. This may not be the best one. But it didn't hurt at all . The time you spend in the above phase are really worth since it reduce all of confusion latter during coding. DO NOT JUMP INTO CODING BEFORE YOU UNDERSTAND the BIG PICTURE and how the small components fit together to make the big picture.
You can view the demo application which I developed for my husbands's office requrements. http://www.webappcabaret.com/maha/index.html I followed the above procedure and finished it in a short term. Of course I got help from javaranch now and then.
Also note that don't get diverted from your goal. If you see another application, if there is anything useful, just think about the useful part alone, not everthing. Divide the overall time you have for the above phases and see if you can meet them. We may not be correct at all times. But atleast we should have some control of the time. The experience you get from this project will deinitly help you in your next one. Of course , in the next project your development speed will be faster than this one since you can make use of some of your comp for the next.
With best wishes,
Maha anna

[This message has been edited by maha anna (edited November 26, 2000).]
 
Siva Jagadeesan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Maha:
Thank you very much . I wish u r my teacher in my uni L .
Anyway I infact did my prototype as an application. As u know I am quite new to servlets and jsp. So it is difficult for m to change my mindset from stand alone application to web application, as the latter is stateless.
The part I am really confused is the create test use case (as the revise test and take test both depend on this use case) In the prototype it was easy for me to implement this . Okay let me tell how I implemented it in my prototype. When the professor selects the course number , the test number s already present in the test are shown with a text box for the user to enter the new test number(which is validated ) . Then create question screen opens . it has a question test box , 3 radio buttons for the question type (multiple choice , true/false , short answer ) according to the selection in the question type the layout changes (like if mulptple choice is selected a 4 raedion button is present ) . I did that using card layout . This is where I am stuck .how am I goin to do the same thing in my web. Okay hwo do u think I can implement this.
As u said I am goin to first do my design of the system . But before doin that , I should be sure how am I goin to design that part. Can u pls be guide me here .
Thank you
Rgds
Siva
 
maha anna
Ranch Hand
Posts: 1467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Send the prototype appln to my emailid. Let me have clear idea about how the end appln will look.
regds
maha anna
 
Siva Jagadeesan
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Maha:
Thank you for ur concern .
i have emailed u the code
rgds
Siva
 
You have to be odd to be #1 - Seuss. An odd little ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic