Recently, I wrote a JSP video. There is no big problem. Basically, I can understand it and implement it like a gourd. When I wrote an SQL query statement last night, I did not miss a field. It takes 10 minutes to locate the problem. It means that the sleep has been postponed for 10 minutes! Cup!
The specific function is to modify and save a table. Here, the table structure is (ID, name, level), where ID increases automatically. To modify and save the data on the page, you just need to retrieve the data from the table and return it to the display on the page. You can change the data based on the displayed content, and then submit and save the data.
When you enter the modification interface, you can call the data in the servlet to retrieve the data. The data retrieval code is as follows: (you can call this method)
Code:
- Public void precategory (httpservletrequest request,
- Httpservletresponse response) throws servletexception, ioexception {
- String id = request. getparameter ("ID ");
- String SQL = "select ID, name, level from category where id =" + ID;
- // String SQL = "Select name, level from category where id =" + ID; queries with fewer IDS
- CATEGORY Category = NULL;
- Queryrunner QR = dbhelper. getqueryrunner ();
- Try {
- List list = (list) QR. Query (SQL, new beanlisthandler (category. Class ));
- System. Out. println ("previous list =" + list. Size ());
- Category = (Category) list. Get (0 );
- } Catch (sqlexception e ){
- E. printstacktrace ();
- }
- System. Out. println ("previous ID =" + category. GETID ());
- System. Out. println ("name =" + category. getname ());
- System. Out. println ("level =" + category. getlevel () before uploading ());
- Request. setattribute ("category", category );
- Request. getrequestdispatcher ("/editcategory. jsp"). Forward (request, response );
- }
It seems that there is nothing wrong, but it is not successful when executing update insertion. It turns out that the id value here is null. I just knew it clearly through background printing. The comments are the SQL statements with errors, which I personally think are hidden.
After the submission, another database data insertion action is executed. If no error is reported, (insertion fails) The new page is returned. So we have to go back to this page along with the new page.