JSP things (4) -- DWR implements cascade & JSP page Query

Source: Internet
Author: User

Date: 2009.05.07

 

Problem:

(1) Use DWR to implement three-layer cascade: function implementation, but the object in JS cannot be converted to the custom object videocateroy

(2) query JSP pages: How to Use STR returned by Js for SQL statements

 

1. Use DWR to implement layer-3 Cascade

1. Expected Implementation Structure Analysis

Grade 7

--- Last semester

------- Chinese

------- Mathematics

------- English

--- Next semester

------- Chinese

------- Mathematics

------- English

2. Write a Java class: getchildcategorybyparentid (int id)

Package COM. gslsoft. dao; <br/>/* search for sub-category by parent class ID */<br/> @ suppresswarnings ("finally ") <br/> public list <videocategory> getchildcategorybyparentid (int id) <br/>{< br/> string SQL = "select * From video_category where parentid = '" + ID + "'"; <br/> List <videocategory> List = new arraylist (); <br/> videocategory Category = NULL; <br/> try {<br/> cachedrowset rs = dbconnection. getresultset (SQL); <br/> while (RS. next () {<br/> Category = new videocategory (); <br/> category. setname (RS. getstring ("name"); <br/> category. setremark (RS. getstring ("remark"); <br/> category. setlevel (RS. getint ("level"); <br/> category. setimage (RS. getstring ("image"); <br/> category. setcategoryid (RS. getint ("ID"); <br/> list. add (category); <br/>}< br/> Rs. close (); <br/>}catch (Java. SQL. sqlexception e) {<br/> logger. log (logger. error, <br/> "datarepository_getvideofilebycategoryid: With categoryid =" + id); <br/> logger. log (logger. error, E. tostring (); <br/>}finally {<br/> return list; <br/>}< br/>}

 

3. Compile the WEB-INF/DWR. xml: The specific configuration instructions are given in the previous chapter.

<? XML version = "1.0" encoding = "GBK"?> <Br/> <DWR> <br/> <allow> <br/> <create creator = "new" javascript = "videocategoryservice"> <br/> <Param name =" class "value =" com. gslsoft. service. videocategoryservice "/> <br/> </create> <br/> </allow> <br/> </DWR> </P> <p>

 

4. Compile the test. jsp page

<% @ Page Language = "Java" contenttype = "text/html; charset = GBK "pageencoding =" GBK "%> <br/> <% @ taglib uri =" http://java.sun.com/jstl/core "prefix =" C "%> <br/> <% @ page Import = "Java. util. * "%> <br/> <% @ page import =" com. gslsoft. service. * "%> <br/> <% @ page import =" com. gslsoft. model. * "%> <br/> <HTML> <br/> <pead> <br/> <title> File Upload </title> <br/> <LINK rel =" stylesheet "href = ".. /.. /CSS/x_css1.css "mce_href =" CSS/X _ Css1.css "type =" text/CSS "> <br/> <MCE: Script Type = 'text/JavaScript 'src ="/APP/DWR/interface/videocategoryservice. JS "mce_src =" app/DWR/interface/videocategoryservice. JS "> </MCE: SCRIPT> <br/> <MCE: Script Type = 'text/JavaScript 'src ="/APP/DWR/interface/videocategory. JS "mce_src =" app/DWR/interface/videocategory. JS "> </MCE: SCRIPT> <br/> <MCE: Script Type = 'text/JavaScript 'src ="/APP/DWR/engine. JS "mce_src =" app /DWR/engine. JS "> </MCE: SCRIPT> <br/> <MCE: Script Type = 'text/JavaScript 'src ="/APP/DWR/util. JS "mce_src =" app/DWR/util. JS "> </MCE: SCRIPT> <br/> <MCE: Script Type = 'text/JavaScript '> <! -- <Br/> // obtain the last semester Based on the grade id <br/> function queryterm () <br/>{< br/> // var gradeid = $ ("selectgrade "). value; <br/> var gradeid=window.doc ument. getelementbyid ("selectgradea "). value; <br/> // not selected by default <br/> If (gradeid = 0) <br/>{< br/> specify parameter Doc ument. getelementbyid ("selectterma "). options. length = 0; <br/> too many Doc ument. getelementbyid ("selectsubjecta "). options. length = 0; <br/>}< br/> else <br/> {<br/> videocategoryservice. getchildcategorybyparentid (gradeid, termcallback); <br/>}</P> <p> function termcallback (data) <br/>{< br/> Please specify Doc ument. getelementbyid ("selectterma "). options. length = 0; </P> <p> for (VAR I = 0; I <data. length; I ++) {<br/> alert (data. length); <br/> alert (typeof (data [I]); <br/> VaR value = videocategoryservice. convertvideocategory (data [I]). getcategoryid (); <br/> var text = videocategoryservice. convertvideocategory (data [I]). getname (); <br/> var option = New Option (text, value ); <br/> // create an option object based on the values marked by each set of values and text. <br/> try {<br/> specify parameter Doc ument. getelementbyid ("selectterma "). options. add (option); // Add the option object to the second drop-down box <br/>} catch (E) {<br/>}</P> <p> var termid = too many Doc ument. getelementbyid ("selectterma "). value; <br/> alert (termid); <br/> videocategoryservice. getchildcategorybyparentid (termid, subjectcallback); </P> <p >}</P> <p> function querysubject () <br/>{< br/> var termid = too many Doc ument. getelementbyid ("selectterma "). value; <br/> videocategoryservice. getchildcategorybyparentid (termid, subjectcallback); <br/>}</P> <p> function subjectcallback (videocategory) <br/>{< br/> specify parameter Doc ument. getelementbyid ("selectsubjecta "). options. length = 0; <br/> for (VAR I = 0; I <videocategory. length; I ++) {<br/> // VaR value = videocategory [I]. categoryid; <br/> // var text = videocategory [I]. name; <br/> var option = New Option ("text", "value "); <br/> // create an option object based on the values marked by each set of values and text. <br/> try {<br/> specify parameter Doc ument. getelementbyid ("selectsubjecta "). options. add (option); // Add the option object to the third drop-down box <br/>} catch (E) {<br/>}</P> <p> function Change1 () <br/>{< br/> queryterm (); <br/>}</P> <p> function Change2 () <br/>{< br/> querysubject (); <br/>}< br/> // --> </MCE: SCRIPT> <br/> </pead> <br/> <body> <br/> <p> </P> <br/> <form method = "Post" Action = "uploadm. JSP "enctype =" multipart/form-Data "> <br/> <Table id =" Table1 "bgcolor =" # e1efcb "border =" 0 "cellpadding =" 4 "cellspacing = "0" style = "width: 100% "> <br/> <tbody> <br/> <tr> <br/> <TD bgcolor =" # f7f7f7 "style =" width: 80px "> <br/> category selection: </TD> <br/> <TD colspan = "5"> <br/> <% <br/> List <videocategory> listgrade, listterm, listsubject; <br/> videocategoryservice service1 = new videocategoryservice (); <br/> listgrade = service1.getvideocategorybylevelid (1); <br/> // listterm = service1.w _ getchildcategorybyparentid (integer. parseint (request. getparameter ("selectgrade"); <br/> listsubject = service1.getvideocategorybylevelid (3 ); <br/> %> <br/> <select name = "selectgradea" style = "width: 120px" onchange = "queryterm (); "> <br/> <option selected =" selected "value =" 0 "> <br/> select grade... <br/> </option> <br/> <% <br/> for (INT I = 0; I <listgrade. size (); I ++) <br/>{< br/>%> <br/> <option value = "<% = listgrade. get (I ). getcategoryid () %> "> <% = listgrade. get (I ). getname () %> </option> <br/> <% <br/>}< br/>%> <br/> <% <br/> listterm = service1.getchildcategorybyparentid (3 ); <br/> %> <br/> </SELECT> <br/> <select name = "selectterma" style = "width: 120px" onchange = "querysubject (); "> <br/> <option selected =" selected "value =" 0 "> <br/> select a semester... <br/> </option> <br/> </SELECT> <br/> <select name = "selectsubjecta" style = "width: 120px "onchange =" "> <br/> <option selected =" selected "value =" 0 "> <br/> select a subject... <br/> </option> <br/> </SELECT> <br/> </TD> <br/> </tr> <br/> </tbody> <br/> </table> <br/> </form> <br/> </body> <br/> </ptml>

 

5. Running Error

 

6. Problem:

How does one convert the data [I] type object to the custom videocategory type?

 

7. Solutions

(1) Add in DWR. xml:

// Videocategory indicates the User-Defined type

<Convert converter = "Bean" match = "com. gslsoft. model. videocategory"/>

(2) Use JSP pages directly

Data [I]. ID gets its ID attribute, instead of calling its attribute using the GETID () method.

--------------------------------------------

So far, the problem of using DWR to solve layer-3 cascade has been completely solved.

Ii. jsp Query

1. Use conditions to determine the search keywords

Alert ("the query condition is: where categoryid = '" specified when using Doc ument. getelementbyid ("selectsubject1"). Value + "'");

2. Write Java class:

Public list <videofile> getallvideofileinfowithkey (string key, int start, int limit)

3. Problem:

How can I transmit a search keyword as a parameter to a Java class as a parameter?

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.