File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes Insert after submit form Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Insert after submit form" Watch "Insert after submit form" New topic

Insert after submit form

manu chaox
Ranch Hand

Joined: Apr 10, 2006
Posts: 110
I have a form in JSP which displays select list of colors. There is button "Submit" which post data from selected item of select list and branche to other page.

I would like to insert row to database within press button "Submit".

I prepared public void insertVote(String color_idfk) in

and now I would like to use this function in JSP, but I don't know how.
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33132

First of all, it is recommended to do this in a servlet rather than a JSP. When you submit the page, it would go to a servlet. The servlet would call your method and then forward to another JSP.

If you absolutely have to do this purely in JSP, you need to add a scriplet with the method call at the beginning of the JSP you are having the submit go to. This approach is much harder to maintain and troubleshoot.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
manu chaox
Ranch Hand

Joined: Apr 10, 2006
Posts: 110
and is it possible to put only some as <% accessDB.insertVote("2"); %> ?

I prepare function in :

But if i use <% accessDB.insertVote("2"); %> then


org.apache.jasper.JasperException: Exception in JSP: /index.jsp:16

14: <%-- create an instance of List, then retrieve SubjectNames --%>
15: <% List colors=accessDB.getColors(); %>
16: <% accessDB.insertVote("2"); %>
18: <%-- make list accessible to page --%>
19: <% request.setAttribute("colors", colors); %>

[ August 18, 2007: Message edited by: manu chao ]
I agree. Here's the link:
subject: Insert after submit form
It's not a secret anymore!