mustafa
mustafa

Reputation: 109

Connect database using JSP

I connected to database using jdbc driver in JSP and I want to learn what is the best way to connect database? Connect database in jsp is a good way? if not what is the best way ?

Upvotes: 1

Views: 939

Answers (2)

Charaf JRA
Charaf JRA

Reputation: 8334

NO.Its not a good way.Read more about MVC Design Pattern to understand.

Upvotes: 1

Aniket Kulkarni
Aniket Kulkarni

Reputation: 12983

Programming Practices

In general, avoid writing Java code (declarations, scriptlets and expressions) in your JSP pages, for the following reasons:

  • Syntax errors in Java code in a JSP page are not detected until the page is deployed. Syntax errors in tag libraries and servlets, on the other hand, are detected prior to deployment.

  • Java code in JSP pages is harder to debug.

  • Java code in JSP pages is harder to maintain, especially for page authors who may not be Java experts.

  • It is generally accepted practice not to mix complex business logic with presentation logic. JSP pages are primarily intended for presentation logic.

  • Code containing Java code, HTML and other scripting instructions can be hard to read.

  • The JSP 2.0 Specification is deemphasizing scriptlets in favor of a much simpler expression language. It will be easier to evolve your JSP pages to JSP 2.0-style programming if Java code is not used in your pages.

Oracle docs

Upvotes: 1

Related Questions