• Post Reply Bookmark Topic Watch Topic
  • New Topic

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
 
Ranch Foreman
Posts: 159
3
Java MySQL Database Spring
  • 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
Ranch Foreman
Posts: 159
3
Java MySQL Database Spring
  • 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
Ranch Foreman
Posts: 159
3
Java MySQL Database Spring
  • 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
Ranch Foreman
Posts: 159
3
Java MySQL Database Spring
  • 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
Ranch Foreman
Posts: 159
3
Java MySQL Database Spring
  • 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)
 
Ranch Foreman
Posts: 3130
37
  • 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
Ranch Foreman
Posts: 159
3
Java MySQL Database Spring
  • 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!