Results 1 to 20 of 22
- 02-03-2010, 10:29 PM #1
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
can you tell how transfer a List eg. created as...between files jsp/java
well can you tell how transfer a List eg. created as
from bean to jsp or from bean to bean or from jsp call to bean, and appear contents on screen or populate a Table(db) ?Java Code:public List getLineList() { // this in file beans.OrderTotals return lineList; } public static void addPlant(OrderPlantItem orderPlantItem) { // OrderPlantItem is a DTO bean lineList.add( orderPlantItem ); }
Java Code://this in file beans.AddOrder ........ public String updateTables(OrderTotals OrderTotals2, List lineList2) { // void String sqlCommand1= "INSERT INTO Customers VALUES('0011','"+this.getCustName()+"','"+this.getCustStreet()+"','"+this.getCustCity()+"','"+this.getCustState()+"','"+this.getCustZip()+"','2')" ; String sqlCommand2= "INSERT INTO Orders VALUES('1011','0011','"+new java.util.Date()+"','"+new java.util.Date()+"',"+OrderTotals2.getTotal()+","+OrderTotals2.getShipping()+","+OrderTotals2.getTax()+")" ; String url = "jdbc:odbc:plants"; //dsn plants String user=""; String password=""; try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn=DriverManager.getConnection ("jdbc:odbc:plants", user, password); sttmnt=conn.createStatement(); sttmnt1=conn.createStatement(); sttmnt2=conn.createStatement(); //get statement object }catch (Exception exception) { //return (exception.getMessage()); } // end of catch finally { // } try { sttmnt.executeUpdate(sqlCommand1); //Object[] lineList2 = lineList5.toArray(); for (int i = 0; i < lineList2.size(); i++) //lineList2.length { OrderPlantItem lineItem0 = (OrderPlantItem)lineList2.get(i); String sqlCommand3= "INSERT INTO OrderDetail VALUES('1011',"+i+1+","+lineItem0.getPlantID()+","+lineItem0.getQty()+","+lineItem0.getSubtotal()+")" ; sttmnt2.executeUpdate(sqlCommand3); } sttmnt1.executeUpdate(sqlCommand2); } // end of try catchJava Code:<jsp:useBean id="add" scope="session" class="beans.AddOrder" /> <jsp:useBean id="AddChoosePlant" scope="session" class="beans.OrderTotals" /> <% // this code part in file confirm shopping purcase confirm.jsp add.updateTables(AddChoosePlant,AddChoosePlant.getLineList()); %>
- 02-04-2010, 09:13 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
I honestly don't understand the question, however I will say that you need to rework that db code.
You should be using PreparedStatements, and not Statements...binding in the variables, and not concatenating them.
You're eating exceptions. You have to at least print the stack trace. I mean, if an exception was thrown you wouldn't have a clue.
Why is the execute for the statement separate from the creation of the statement? If the creation fails (due to a thrown exception) you don't want to simply plow on and try and execute!
- 02-04-2010, 05:14 PM #3
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
1)db Q
in a for body that executes a query like above:
sttmnt2.executeUpdate(sqlCommand3);
the
sttmnt2=conn.createStatement();
must appear outside loop? is this above correct?
2)Q:List object data appear in jsp(view) or enter in db-table(model) like cartItems in cart
When I have a List obj contains cartItems objects (eg shopping cart) already populated in a javabean, and want to appear this data to the next jsp file(view) and then enter them in database table via next confirm.jsp that use a process bean(model), what to do to transfer this List Object?
- 02-05-2010, 09:32 AM #4
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
1) Use a PreparedStatement. Then prepareStatement() outside the loop, and inside the loop bind (setInt(), setString() etc) and execute. You do not want to be using a Statement in this case.
2) Store them in the session?
- 02-05-2010, 10:43 AM #5
Member
- Join Date
- Feb 2010
- Posts
- 6
- Rep Power
- 0
please note the whole bean.OrderTotals that List built and is in, belongs to a sessio
please note the whole bean.OrderTotals that List built and is in, belongs to a session but I do NOT know how handle the transfer, mainly the reference of objs(List)?
- 02-05-2010, 10:54 AM #6
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
What do you mean "transfer"?
If it's in the session then it's accessible for any request that is part of the same session.
- 02-05-2010, 11:02 AM #7
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
If the bean is in scope on the page, you use EL to access it
e.g ${AddChoosePlant.lineList} to access the list returned by the getLineList method.
Better load those values in the constructor of the bean though so that your getter is always a one liner. You don't want to keep making unnecessary calls to the database.
- 02-05-2010, 11:45 AM #8
Member
- Join Date
- Feb 2010
- Posts
- 6
- Rep Power
- 0
is this call to session bean , obj List ...?
Can you explain inmore detail? I do not know how to retieve obj, anyway I get error I think is from below:
is this call to session bean , obj List ...?
Do you want attach complete code files?
add.updateTables(AddChoosePlant,AddChoosePlant.get LineList()); // jsp confirm
>>>
//process bean
public String updateTables(OrderTotals OrderTotals2, List lineList2) {
....
sttmnt2=conn.createStatement();
....
for (int i = 0; i < lineList2.size(); i++) //lineList2.length
{
OrderPlantItem lineItem0 = (OrderPlantItem)lineList2.get(i);
String sqlCommand3= "INSERT INTO OrderDetail VALUES('1011',"+i+1+","+lineItem0.getPlantID()+"," +lineItem0.getQty()+","+lineItem0.getSubtotal()+") " ;
sttmnt2.executeUpdate(sqlCommand3);
}
>>>
- 02-05-2010, 11:57 AM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
What error?
- 02-05-2010, 03:59 PM #10
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
error below...attach files
error below...attach files
index.htm->OrderPlantItem.jsp(OrderPlantItem.java)->OrderTotals.jsp(OrderTotals.java)->customerDataInsert.html->confirm.jsp(AddOrder.java)
Q: in netbeans where found servlets files made from jsp during compilation in case an error prompts me...?
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: javax.servlet.ServletException: java.lang.NoSuchMethodError: beans.AddOrder.updateTables(Lbeans/OrderTotals;Ljava/util/List;)V
org.apache.jasper.servlet.JspServletWrapper.handle JspException(JspServletWrapper.java:522)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:398)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:390)
root cause
javax.servlet.ServletException: java.lang.NoSuchMethodError: beans.AddOrder.updateTables(Lbeans/OrderTotals;Ljava/util/List;)V
org.apache.jasper.runtime.PageContextImpl.doHandle PageException(PageContextImpl.java:852)
org.apache.jasper.runtime.PageContextImpl.handlePa geException(PageContextImpl.java:781)
org.apache.jsp.confirm_jsp._jspService(confirm_jsp .java:141)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:390)
root cause
java.lang.NoSuchMethodError: beans.AddOrder.updateTables(Lbeans/OrderTotals;Ljava/util/List;)V
org.apache.jsp.confirm_jsp._jspService(confirm_jsp .java:107)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:374)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:342)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:267)
javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
org.netbeans.modules.web.monitor.server.MonitorFil ter.doFilter(MonitorFilter.java:390)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.18 logs.
Apache Tomcat/6.0.18
- 02-05-2010, 04:04 PM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
Seems pretty clear to me. There is no updateTables method in AddOrder.
- 02-05-2010, 06:24 PM #12
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
but in bean AddOrder.java exist...this that add to database (I also tried appear data in a jsp(view) prior add to db,...(commentted code in OrderTotals.jsp) but failed).
I think for sure error is in representation of List obj in the other file, how to reference?
AddOrder.java:
......................
public String updateTables(OrderTotals OrderTotals2, List lineList2) { // void
String sqlCommand1= "INSERT INTO Customers VALUES('0013','"+this.getCustName()+"','"+this.get CustStreet()+"','"+this.getCustCity()+"','"+this.g etCustState()+"','"+this.getCustZip()+"','2')" ;
String sqlCommand2= "INSERT INTO Orders VALUES('1013','0013','"+new java.util.Date()+"','"+new java.util.Date()+"',"+OrderTotals2.getTotal()+","+ OrderTotals2.getShipping()+","+OrderTotals2.getTax ()+")" ;
String url = "jdbc:odbc:plants"; //dsn plants
- 02-05-2010, 08:18 PM #13
Moderator
- Join Date
- Apr 2009
- Posts
- 10,460
- Rep Power
- 16
This error:
NoSuchMethodError: beans.AddOrder.updateTables(Lbeans/OrderTotals;Ljava/util/List;)
means that that method does not exist.
That it exists in the code you've posted, does not mean it exists inthe code you're running.
- 02-05-2010, 09:55 PM #14
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
not reference well the List (to get obj List of objs from one bean to other)
please note I use netbeans and this is along other beans...
well may not reference well the List (to get obj List of objs from one bean to other) ?
- 02-06-2010, 02:06 AM #15
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Yes well you can't call a method on bean A using a reference to bean B.
The id you use in the useBean directive is associated with a bean of the class that you specify as the class attribute only.
- 02-06-2010, 08:37 AM #16
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
what are the 2-3 correct statements then?
- 02-08-2010, 02:48 PM #17
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
I also do not used <>, at List<obj> statement, is it required/correct syntax? I will cover Generics[List objs of Java SE] chapter in about one month, may you answer now?
- 02-08-2010, 06:09 PM #18
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
I don't really understand your latest question.
Did you understand my last explanation?
- 02-08-2010, 10:13 PM #19
Senior Member
- Join Date
- Oct 2008
- Posts
- 116
- Rep Power
- 0
in List<obj> statement in the code, I did not used angle brackets, it will also function?
If you give the correct statements rather, it will be great, otherwise I will review again your answer and code today or tomorrow since is late 24:00 here, thks! again...
- 02-09-2010, 07:20 AM #20
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Similar Threads
-
how to get the list of war files
By vijayabaskar in forum Java ServletReplies: 0Last Post: 04-03-2009, 08:39 AM -
how to list certain files in a given directory in java
By corpusluteum in forum New To JavaReplies: 6Last Post: 09-24-2008, 12:19 AM -
List all the files in the current jar
By Srikanth_From_Moon in forum New To JavaReplies: 0Last Post: 06-14-2008, 08:42 AM -
can java.io.File create a list of all files and folders.
By MattStone in forum New To JavaReplies: 20Last Post: 12-17-2007, 03:20 PM -
How can I get list of files in a directory
By karma in forum New To JavaReplies: 2Last Post: 12-14-2007, 11:20 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks