File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Checking the accountname is exist in database or not Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Checking the accountname is exist in database or not" Watch "Checking the accountname is exist in database or not" New topic
Author

Checking the accountname is exist in database or not

Perumalla LakshmanaRao
Greenhorn

Joined: Sep 03, 2006
Posts: 9
Hi All,
I have one jsp page,in that 3 fields there like account number,account type,comment and one submit button is there.At first time if I entered one account number and click on submit it's going to insert into db.If suppose I entered with the same account number then it must show one pop up window like The account entered is already exists do you want to update the information.So,how I will check this account number into the databse?For this I written code like this

<%!Iterator iterList;
String faccntnum = request.getParameter("ac_accountNumber");
String aaccntnum;
CaseAccountInfoVO caseAccountInfoVO;
boolean aacntnumflag = false;
int i=0;
%>
<%
iterList = listacco.iterator();

while (iterList.hasNext()) {


caseAccountInfoVO = (CaseAccountInfoVO) iterList.next();
aaccntnum = caseAccountInfoVO.getAc_accountNumber();
/* comparing accntnum with existing account numbers in database*/
if(aaccntnum == faccntnum)
{
aacntnumflag = true;
break;
}


}
and I written javascript function also.But the problem is,it's showing the pop up window if I entered same account number and for different account number also it's showing the pop up window.If you know any other logic please help to me.
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
well, this requires db-access and therefore is no jsp-funcitonality.

-> a action has to check wether the account number exists.

so submit a html-form to an appropriate struts-action which checks wether the number is okay or not. if okay, show a success page / message, if not, show a error page / jsp.

hope it helps,
jan
Chris Boldon
Ranch Hand

Joined: Aug 10, 2006
Posts: 190
In addition, one of the nice things about Struts is it enables you to pull scriptlets out of your JSP. This is good practice and in future programs you should try and include as little java code as you can.
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
why is it good to take scriplets out? serious question...
Chris Boldon
Ranch Hand

Joined: Aug 10, 2006
Posts: 190
It gives your code more reusability and more clearly defined code boundaries. The reason we create tiers. Making your code more easily read and edited. In a commercially deployed environment it also reduces the chance and ease of exploits noticably.
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
hm. reusability?

i'd say that a jsp coded with jstl is as reusable as one scriptlets. or do you want to reuse jsp-fragments? (if so, which i doubt, write fragments and reuse then...)

code boundaries - what do you mean with that? i say if i need boundaries / seperations / modules on a jsp, i need to rethink my component concept.

here come my points against jstl:
- lost type-safety
- easy to mistype (no ide supports you if you access bean properties)
- hard to debug
- hard to test (that's a killer argument in my eyes, jstl is evaluated at execution time in the service() method, not at development time)
- new language format to learn (hey, i speak java, and web-designers do at least understand javascript. they are able to write scriplets. all syntax you need are loops, if / else and maybe some assignments
- f***ing hard to refactor.

just my 5 cents...

jan :-)
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
When faced with the decision about creating even marginally complex presentation logic using jstl, or scriplets I choose...neither. I would much rather push the code up into my form, my action, a utility class or even up into the business tier. That way it can be reused in other pages or functionality.

I agree with the type-safety (though the lack of type-safety offers some flexibility) and IDE support issues. I don't understand the debug and test comments, because I find that both are equally hard to test and debug. New language? I guess each tag has attributes that you need to learn, but jstl tags are expressed in XML. I find that a page with a lot of scriptlets is very hard to read.

- Brent
Jan Groth
Ranch Hand

Joined: Feb 03, 2004
Posts: 456
i completely agree that all kind of logic other then the pure code needed for the display belongs into the controller.

my test / debug issue is the following:



looks okay, but might return nothing (worst case) or an exception (better case) if the according bean property is named "getZipcode()".

this is not discovered before execution time.

very very bad.

for the records:

fails immediately.

:-)

cheers,
jan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Checking the accountname is exist in database or not
 
Similar Threads
Pop-Up Window and getParameter()
View Refresh after form closed
Submit problem when another pop-up window opens
How to get value from formbean
How to get Javascript popup window