| Author |
Insert after submit form
|
manu chaox
Ranch Hand
Joined: Apr 10, 2006
Posts: 110
|
|
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
internet detective
Marshal
Joined: May 26, 2003
Posts: 26141
|
|
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.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, 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 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 ]
|
 |
 |
|
|
subject: Insert after submit form
|
|
|