• Post Reply Bookmark Topic Watch Topic
  • New Topic

Fetching data from database when submit/click the button  RSS feed

 
Rahul kumar verma
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm using jstl with html in this code if hard-coded in input field, when click on submit button not display the data from database in my project. But while creating one more jsp page and paste these code into jsp and when run jsp page it shows the data regarding hard coded. But it not working in my project when combining.


 
Dave Tolls
Rancher
Posts: 2914
36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't see a great deal of JSTL in that code.

You should not have Java code in your JSP like that.

Your form should submit to a servlet which will call a service that returns a List<SomeModel> that can then be forwarded to the JSP page for display, allowing you to use JSTL to format it.

That way you disconnect your display stuff from the Java code, and can test each bit and (hopefully) isolate any issues.
 
Rahul kumar verma
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its work when created in new project as well change the file name and run directly jsp page then it also work...
 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul kumar verma wrote:Its work when created in new project as well change the file name and run directly jsp page then it also work...

Programming is not about how to get a solution.
It is about how to get a solution in correct way.
What Dave explained is the correct way of doing things in web application.
 
Rahul kumar verma
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for my side Tapas and Dave  because I'm using scriptlet only of JSP and according to that fetching data from database on click buttom
 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rahul kumar verma wrote:Sorry for my side Tapas and Dave  because I'm using scriptlet only of JSP and according to that fetching data from database on click buttom

Yes I understand.
That is why we are suggesting you to rectify these practices.
Using scriplet is tempting and is OK in very small JSPs.
Once you are in actual projects and size of application increases, it will be very difficult to maintain and debug.
Separating the view and the logic will make your life easier.
And EL has been the standard in JSP since 14-15 years. Scriplets should be avoided.
 
Rahul kumar verma
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Tapas

One more thing when run this page only instead of whole project then its working fine as what I want but at whole project its not display data when click on submit button
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I added code tags to your post, Please be sure to use code tags in the future.

Do not use Java code in your JSP. It's been obsolete for 15 years. Do not uppercase your HTML. That's also an obsolete practice that makes the code harder to read.

See your other post with regards to learning how JSP works. I think you are having the same problem here.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!