• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Insert after submit form

 
manu chaox
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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 AccessDB.java
http://www.netbeans.org/kb/55/mysql-webapp.html#interfacingDatabase

and now I would like to use this function in JSP, but I don't know how.
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 34071
331
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manu,
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.
 
manu chaox
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
and is it possible to put only some as <% accessDB.insertVote("2"); %> ?

I prepare function in AccessDB.java :





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

exception

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

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


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:504)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:368)
[ August 18, 2007: Message edited by: manu chao ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic