Friday, December 25, 2009

Numéro Série Néro 3.1

transmission of data through ajax with jquery jquery

we will develop the following example
unlike the previous example is that now you can work with
file structures, and we will work with
a driver for our example. but let the sample.

1 .- First we will create our class book, encapsulated
like god, solomante the get the attributes of the class
because we SETI using a constructor.


public class Book {private String title;
private String type;
private int qty;
private String comment;

book () {}


Book (String title, String type, int qty, String comment) {

this.titulo = title;
this.tipo = type;
this.qty = qty;
this.comentario = comment;}



getTitulo public String () {
return title;}


getTipo public String () {return type
;
} public int

getQty ( )
{return qty;}


getComments public String () {return
comment;
}}




2 .- as a second step we create class books, which we manage objects
class book.

import java.util .*;


{public class

books Map books = new LinkedHashMap ();
public
books () {

books.put (11, new book (
"Java Swing "," java ", 1," for desktop applications "));
books.put (27, new book (
" php "," daniel ", 1," book to start php "

)
)

} public
book fetch (int id) {return books.get (id);}
fetchIds public Set () {return books.keySet ();}}


3 .-
after we create our archive of
getbook_as_table.js type and add the following javascript.

$ (function () {
$ ("# button"). Click (function () {$
. Ajax ({
type: "GET", url
"book_table.jsp"
data: {id $ ("# sel"). val ()},
success: function (data) {
$ ("# out"). html (data)

}})
})}
)

4. - now let's create the jsp pages, the first will
getbook_as_table.jsp


\u0026lt;% @ page contentType = "text / html"%>

\u0026lt;% @ page pageEncoding = "UTF-8"%>

\u0026lt;! DOCTYPE HTML PUBLIC "- / / W3C / / DTD HTML 4.01 Transitional / / EN"

"http://www.w3.org/TR/html4/ loose.dtd ">

\u0026lt;% @ page import =" java.util .* "%>

\u0026lt;% @ page import =" model .* "%>

\u0026lt;JSP: useBean id = "book" scope = "session" class = "modelo.libros" />

\u0026lt;html>

\u0026lt;head>

\u0026lt;meta http-equi = "Content-Type" content = "text / html; charset = UTF-8 ">

\u0026lt;title> selection de libro </title>

<script type="text/javascript" src="js/jquery-1.3.1.js"></script>

<script type="text/javascript" src="js/errors.js"></script>

<script type="text/javascript" src="js/getbook_as_table.js"></script>

</head>

<body>

<h3>Buscar libro</h3>

<select id="sel">

<% for (Integer i: books.fetchIds ()) {%>

\u0026lt;option value ="\u0026lt;%= i% %>">\u0026lt;%= i> \u0026lt;/ option>

\u0026lt; ;%}%>

\u0026lt;/ select>

\u0026lt;button id="button"> Search Book \u0026lt;/ button>

\u0026lt;br /> \u0026lt;br />

Book Selection :

\u0026lt;div id="out"> \u0026lt;/ div>

\u0026lt;/ body>

\u0026lt;/ html>

and last page

book_table.jsp
\u0026lt;% @ page contentType = "text / html"%>

\u0026lt;% @ page pageEncoding = "UTF-8"%>

\u0026lt; ,% @ page import = "model .*"%>

\u0026lt;jsp:useBean id="libros" scope="session" class="modelo.libros"/>

\u0026lt;% String id

= request.getParameter ("id") int

id_num = Integer.parseInt (id);

libros.fetch
Book book = (id_num)

book.getComentario comment = String ();

String title = book.getTitulo ();

book.getTipo type = String ();
book.getQty
int qty = ();

%>

\u0026lt;table border = "1" cellpadding = "5" >

\u0026lt;tr>

\u0026lt;td> Title: \u0026lt;/ td> \u0026lt;% = title%> \u0026lt;/ td>

\u0026lt;/ tr>

\u0026lt;tr> ;

\u0026lt;td> type: \u0026lt;/ td> \u0026lt;% = type%> \u0026lt;/ td>

\u0026lt;/ tr>

\u0026lt;tr>

\u0026lt;td> qty: \u0026lt;/ td> \u0026lt;td \u0026lt;% = qty%> \u0026lt;/ td>

\u0026lt;/ tr>

\u0026lt;tr>

\u0026lt;td> comment: \u0026lt;/ td> \u0026lt;td \u0026lt;% = comment%> \u0026lt;/ td>

\u0026lt;/ tr>

\u0026lt;/ table>

on the code, if you do not understand how it works useBean pu eden
find this blok as you work. Here

0 comments:

Post a Comment