java - Extrating data from jsp form to controller and saving them to database -


hello trying save data form database have no idea how continue now. have following code.

i tried using request.getparameter("id") in controller gave me compiler error.

so how data jsp form controller , save them mysql database ?

jsp file

<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <!doctype html> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>insert title here</title> </head> <body>     <form action="productcontroller" method="post">         <p>enter product name :</p> <input id="productname" type="text" name="username"> <br>         <p>enter product serial number :</p> <input id="serialnumber" type="password" name="password"> <br>         <input type="submit" placeholder="submit" />     </form>   </body> </html> 

the controller

@controller @requestmapping("/product") public class productcontroller {      @autowired     private productservice productservice;      @requestmapping("/list")     public modelandview list() {         modelandview modelandview = new modelandview("product/list");         system.out.println("count:" + productservice.getproducts().size());         modelandview.addobject("test", "mytest");         modelandview.addobject("count", productservice.getproducts().size());         modelandview.addobject("products", productservice.getproducts());         return modelandview;     } } 

and product dao

@override public void saveproduct(product product) {     //persist(product);      session session = this.sessionfactory.opensession();     transaction tx = session.begintransaction();     session.persist(product);     tx.commit();     session.close(); } 

you have use name attribute of html element value, request.getparameter("username");


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -