servlet: /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package TLMClient; import java.io.IOException; import java.io.PrintWriter; import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; /** * * @author Administrator */ public class Param extends HttpServlet { /** * Processes requests for both HTTP * <code>GET</code> and * <code>POST</code> methods. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); response.setContentType("text/html"); String name=request.getParameter("saa"); try { System.out.println("sssssssssssssssssssssssssssssssssss"); JspSql j=new JspSql(name); j.getParamList(); // request.setAttribute("JspSql", j.getParamList()); // getServletContext().getRequestDispatcher("addparameter1.jsp").forward(request, response); } catch (Exception ex) { Logger.getLogger(Param.class.getName()).log(Level.SEVERE, null, ex); } PrintWriter out = response.getWriter(); try { /* TODO output your page here. You may use following sample code. */ out.println("<html>"); out.println("<head>"); out.println("<title>Servlet Param</title>"); out.println("</head>"); out.println("<body>"); out.println("</body>"); out.println("</html>"); } finally { out.close(); } } // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code."> /** * Handles the HTTP * <code>GET</code> method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Handles the HTTP * <code>POST</code> method. * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { processRequest(request, response); } /** * Returns a short description of the servlet. * * @return a String containing servlet description */ @Override public String getServletInfo() { return "Short description"; }// </editor-fold> } ==================================================================== java class /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package TLMClient; import com.sun.rowset.CachedRowSetImpl; import java.sql.SQLException; import java.util.ArrayList; import javax.sql.rowset.CachedRowSet; /** * * @author Administrator */ public class JspSql { private CachedRowSet rowSet; private CachedRowSet rowSet1; private CachedRowSet rowSet2; public String sub; // construct TitlesBean object public JspSql() throws Exception { // this.sub=subSystem; System.out.println("=========================="+sub); Class.forName( "oracle.jdbc.OracleDriver" ); rowSet = new CachedRowSetImpl(); rowSet.setUrl( "jdbc:oracle:thin:@//localhost:1521/orcl.ssssw.internet" ); rowSet.setUsername( "ssss" ); rowSet.setPassword( "ssss" ); rowSet.setCommand("select B.HPARAM,B.TYPE_ID,B.NTX,B.NCONDITIONNUMBER,B.MINLIMIT from param_def \"B\",form2param, form\n" + "where B.HPARAM= form2param.hparam \n" + "and form2param.hform =form.hform\n" + "and form.szname2 = '"+sub+"' "); rowSet.execute(); Class.forName( "oracle.jdbc.OracleDriver" ); rowSet1 = new CachedRowSetImpl(); rowSet1.setUrl( "jdbc:oracle:thin:@//localhost:1521/orcl.ssssw.internet" ); rowSet1.setUsername( "ssss" ); rowSet1.setPassword( "ssss" ); rowSet1.setCommand("select szname2 from system order by hsystem "); rowSet1.execute(); Class.forName( "oracle.jdbc.OracleDriver" ); rowSet2 = new CachedRowSetImpl(); rowSet2.setUrl( "jdbc:oracle:thin:@//localhost:1521/orcl.ssssw.internet" ); rowSet2.setUsername( "ssss" ); rowSet2.setPassword( "ssss" ); rowSet2.setCommand("select szname2 from form order by hform "); rowSet2.execute(); } // end GuestDataBean constructor JspSql(String name) { throw new UnsupportedOperationException("Not yet implemented"); } // return an ArrayList of GuestBeans public ArrayList< AddNewFormWithItsParameters > getParamList() throws SQLException { ArrayList< AddNewFormWithItsParameters > paramList = new ArrayList< AddNewFormWithItsParameters >(); rowSet.beforeFirst(); // move cursor before the first row // get row data while ( rowSet.next() ) { AddNewFormWithItsParameters Param = new AddNewFormWithItsParameters(); Param.setIndex( rowSet.getString( 1 ) ); Param.setPackage( rowSet.getString( 2 ) ); Param.setCond( rowSet.getString( 3 ) ); Param.setC( rowSet.getString( 4 ) ); Param.setE( rowSet.getString( 5 ) ); paramList.add(Param); } // end while return paramList; } // end method getGuestList public ArrayList< AddNewFormWithItsParameters > getParamListTree() throws SQLException { ArrayList< AddNewFormWithItsParameters > paramListtree = new ArrayList< AddNewFormWithItsParameters >(); rowSet1.beforeFirst(); // move cursor before the first row // get row data while ( rowSet1.next() ) { AddNewFormWithItsParameters Param1 = new AddNewFormWithItsParameters(); Param1.setNameSubSystem( rowSet1.getString( 1 ) ); paramListtree.add(Param1); } // end while return paramListtree; } public ArrayList< AddNewFormWithItsParameters > getParamListTree1() throws SQLException { ArrayList< AddNewFormWithItsParameters > paramListtree1 = new ArrayList< AddNewFormWithItsParameters >(); rowSet2.beforeFirst(); // move cursor before the first row // get row data while ( rowSet2.next() ) { AddNewFormWithItsParameters Param2 = new AddNewFormWithItsParameters(); Param2.setFormulars( rowSet2.getString( 1 ) ); paramListtree1.add(Param2); } // end while return paramListtree1; } // insert a guest in guestbook database /* public void addParam( AddNewFormWithItsParameters param ) throws SQLException { rowSet.moveToInsertRow(); // move cursor to the insert row // update the three columns of the insert row rowSet.updateString( 1, param.getIndex() ); rowSet.updateString( 2, param.getPackage() ); rowSet.updateString( 3, param.getCond() ); rowSet.updateString( 4, param.getC() ); rowSet.updateString( 5, param.getE() ); rowSet.updateString( 6, param.getN() ); rowSet.updateString( 7, param.getType() ); rowSet.updateString( 8, param.getCCTX() ); rowSet.updateString( 9, param.getCode() ); rowSet.updateString( 10, param.getSign() ); rowSet.updateString( 11, param.getPrec() ); rowSet.updateString( 12, param.getMin() ); rowSet.updateString( 13, param.getMax() ); rowSet.updateString( 14, param.getDescryption() ); rowSet.insertRow(); // insert row to rowSet rowSet.moveToCurrentRow(); // move cursor to the current row rowSet.acceptChanges(); // propagate changes to database } // end method addGuest */ }
//in java code import java.sql.*; import java.util.*; public class GetListData { int i=0; public List dataList(){ ArrayList list=new ArrayList(); try{ //Create Select Clause sQL and get conncetions String SQL_QUERY ="Select * from table"; Query query = con.ececuteQuery(SQL_QUERY); for(Iterator it=query.iterate();it.hasNext();){ Object[] row = (Object[]) it.next(); list.add(row[i]); i++; } session.close(); }catch(Exception e){ System.out.println(e.getMessage()); }finally{ } return list; } } //jsp code <![CDATA[<% Iterator itr; PassStudentIDList list=new PassStudentIDList(); List data=(List)list.get(); for(itr=data.iterator(); itr.hasNext();) { out.print(itr.next()); } %>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)