0

Calling JSP (with data) from ZUL - Separate Java Code from ZUL Files

asked 2011-07-09 13:24:42 +0800

THBG gravatar image THBG
15

updated 2011-07-09 13:25:22 +0800

Hi,

I'm using the following code to insert data into a MySQL database and it works fine.

I'd like to be able to separate the Java code (in the ZSCRIPT tags) into an external JSP file (eg to afterward centralized db connection...) and be able to call submit() method (with data to pass).

I reviewed docs, web and forums but I'm unable to find out how to achieve this.
Does anyone can help me please ?

Thanks
Tom

<?page title="new page title" contentType="text/html;charset=UTF-8"?>

<zk>

<window title="JDBC demo" border="normal">

     <zscript><![CDATA[

     import java.sql.*;

     void submit() {
         //load driver and get a database connetion
         Class.forName("com.mysql.jdbc.Driver");
         Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/test?user=root&password=");
         PreparedStatement stmt = null;

         try {
             stmt = conn.prepareStatement("INSERT INTO test.users (name,address) values(?, ?)");
             //insert what end user entered into database table
             stmt.setString(1, name.value);
             stmt.setString(2, email.value);

             //execute the statement
             stmt.executeUpdate();

         } finally { //cleanup

             if (stmt != null) {
                 try {
                     stmt.close();
                 } catch (SQLException ex) {
                     log.error(ex); //log and ignore
                 }
             }
             if (conn != null) {
                 try {
                     conn.close();
                 } catch (SQLException ex) {
                     log.error(ex); //log and ignore
                 }
             }
         }
     }
     ]]>

     </zscript>
     <vbox>
         <hbox>Name : <textbox id="name"/></hbox>
         <hbox>Email: <textbox id="email"/></hbox>
         <button label="submit" onClick="submit()"/>
     </vbox>
 </window>
</zk>

delete flag offensive retag edit

1 Reply

Sort by ยป oldest newest

answered 2011-07-10 10:03:24 +0800

caclark gravatar image caclark
1753 2 5
http://clarktrips.intltwi...

ZK supports the MVC paradigm. You don't want that code in a JSP. JSP is view technology. Study up on MVC and how to use it with ZK.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-07-09 13:24:42 +0800

Seen: 376 times

Last updated: Jul 10 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More