jsp - Java Desktop-App to Java-Web-App -
i new java-web-programming , non-gui netbeans-codes compiling whenever place jsp tags, gui netbeans-codes full of errors whenever place jsp tags:<%! %> , <% %>. below 1 of netbeans-gui codes simple "salary tagging system" 3 labels corresponding 3 textfields(dspid, dspname,dspsal). right jsp-tagging way?
public class employee extends javax.swing.jframe { // variables declaration private javax.swing.jtextarea disparea; private javax.swing.jtextfield dispid; private javax.swing.jtextfield dispname; private javax.swing.jtextfield dispsal; private javax.swing.jbutton findbutton; private javax.swing.jlabel jlabel1; private javax.swing.jlabel jlabel2; private javax.swing.jlabel jlabel3; private javax.swing.jscrollpane jscrollpane1; // end of variables declaration public employee() { initcomponents(); } @suppresswarnings("unchecked") // <editor-fold defaultstate="collapsed" desc="generated code"> private void initcomponents() { findbutton = new javax.swing.jbutton(); jlabel1 = new javax.swing.jlabel(); jlabel2 = new javax.swing.jlabel(); dispid = new javax.swing.jtextfield(); dispname = new javax.swing.jtextfield(); jscrollpane1 = new javax.swing.jscrollpane(); disparea = new javax.swing.jtextarea(); jlabel3 = new javax.swing.jlabel(); dispsal = new javax.swing.jtextfield(); setdefaultcloseoperation(javax.swing.windowconstants.exit_on_close); findbutton.settext("find"); findbutton.addactionlistener(new java.awt.event.actionlistener() { public void actionperformed(java.awt.event.actionevent evt) { findbuttonactionperformed(evt); } }); jlabel1.settext("employee id"); jlabel2.settext("name"); disparea.setcolumns(20); disparea.setrows(5); jscrollpane1.setviewportview(disparea); jlabel3.settext("salary"); dispsal.settext(" "); }// </editor-fold> private void findbuttonactionperformed(java.awt.event.actionevent evt) { try{ class.forname( "com.mysql.jdbc.driver" ); connection con = drivermanager.getconnection("jdbc:mysql://localhost:3306/emp","root",""); statement statement = con.createstatement(); string query = "select * empinfo "; query +="where empinfo = "+this.dispid.gettext(); if(this.dispname.gettext().length() != 0){ query +=" , name = '"+this.dispname.gettext()+"'"; } if(this.dispsal.gettext().length() != 0){ query +=" , salary = '"+this.dispsal.gettext()+"'"; } //disparea.append("\nyour query :"+query+"\n"); resultset rs = statement.executequery(query); boolean morerecords = rs.next(); if(!morerecords){ disparea.append("sorry,no match!"); this.dispid.settext(""); } do{ this.dispname.settext(rs.getstring(2)); this.dispsal.settext(rs.getstring(3)); this.disparea.settext(rs.getstring(4)); }while(rs.next()); statement.close(); con.close(); } catch(sqlexception e){ disparea.append(""); //outputjtextarea.append(e.getstacktrace().tostring()); //e.printstacktrace(); }catch(classnotfoundexception e){ //e.printstacktrace(); disparea.append(""); } } public static void main(string args[]) { java.awt.eventqueue.invokelater(new runnable() { public void run() { new employee().setvisible(true); } }); }
}`
one way make application both gui , web capable redesign using mvc principle. put separates display part data , processing.
Comments
Post a Comment