• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

How to display result of SQL in alert message using javascript in jsp?  RSS feed

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Below is COUNT SQL statement in jsp. As you can see my dropdown of studentlevel will display the count of each level. If a user clicks on one of the dropdowns, then if the studentlevel achieved the maximum number of 5 people the system will produce an alert message but I failed to do so. I think my method is wrong. Please help me to make it happen.



JAVASCRIPT
 
Rancher
Posts: 309
6
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You shouldn't put you javacode in you jsp. Your dropdown should call a controller that holds the javacode to ecute the query and generate the message, then passes it on to your jsp.

something like:


To call in your jsp
 
Daniel Demesmaecker
Rancher
Posts: 309
6
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
since it's a dropdown, it would be a get not a post, simply set a onClick on your dropdown that calls a url and handle this in your controller
 
nazirah nazri
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for the reply, but do you have any other example so that I can look through it and be able to understand more. Cause I'm still little confused.
 
Daniel Demesmaecker
Rancher
Posts: 309
6
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is an example of a login controller that I've written wen I was experimenting with servlet:
 
Daniel Demesmaecker
Rancher
Posts: 309
6
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this case I first check if the urser is already loged in, if so I redirect him to the homepage.
if not I bind the info of the loginform to a userobject and show the login page.
Then in the post method I can use the object I just created and filled with the info from the form and take apropiate actions based on that.
 
Daniel Demesmaecker
Rancher
Posts: 309
6
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your case you don't have to bind anything, You have to give your dropbox a variable name and call it in your controller with @Pathvariable("nameOfJspVariable)
 
Rancher
Posts: 3600
39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The above assumes that nazirah is using Spring.

Since this is currently a JSP with lots of code I would guess a straight servlet would be more likely.
 
Daniel Demesmaecker
Rancher
Posts: 309
6
Hibernate IntelliJ IDE Java MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:The above assumes that nazirah is using Spring.

Since this is currently a JSP with lots of code I would guess a straight servlet would be more likely.



You're right... I always use spring and forgot to think if he does also
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!