struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Newton <>
Subject Re: How to display data from database to JSP Page in Struts2
Date Fri, 08 Jul 2011 23:32:38 GMT
On Fri, Jul 8, 2011 at 4:25 PM, log2akshat wrote:
> package net.Candidate.application.action;

Again, I would strongly urge you to follow normal Java naming conventions

> import*;
> import java.sql.*;
> import java.util.*;

And again, I would strongly urge you to *not* do all this database
work in the action itself.

> import net.Candidate.application.model.Appform;

If you're using a form object (or "command object" in some frameworks,
akin to the old Struts 1 ActionForm) I'd consider using the
ModelDriven approach.

>        private int onlineID = 0;
> [...]
>                                *int OnlineID = 0;*

You are creating an additional variable, "OnlineID", whereas your
getter method returns the class property "onlineID". This is very
confusing, and at least partially your problem.

>                                String IDqry = "Select OnlineID from applicant
where Email=?";

Note that you may have a race condition here if someone else registers
with the same email, unless you're handling your transactions through
an interceptor somehow, or have DB-level constraints.

>                                setOnlineID(this.onlineID);

Here you pass the class property (0, as initialized) into a method
that does nothing with it.

>                                return "success";

Why do you use "success" here, but:

>                return SUCCESS;

SUCCESS here? Be consistent.

>        public void setOnlineID(int onlineID) {

Why does a method called "setOnlineID" retrieve the ID? Doesn't that
seem backwards to you? Plus I'm not really sure why you need it, since
you have already retrieved the value in the action code above.

Please, *please* refactor your code, clean it up, and pay very close
attention to what the code you're writing is actually doing.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message