• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using vectors in servlets

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im creating an online e-shop. Im trying to add an item to the basket and display items in the basket using vectors within servlets but it dont seem to work. Does anyone know how it is done?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"How to build a shopping cart" is a bit much to post in a forum.
Have you searched the web for servlet/jsp tutorials.

A lot of books and tutorials use a shopping cart in their examples.
 
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vectors work fine in Servlets. there probably is a problem with your implementation. can you post the code?
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I think for you there is probelom is session tracking vector object..

paste the codings...
let us find the solutions

cheers
vasu
 
Davendra Jesani
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ive managed to add items to the basket using beans. This is the following code:

HttpSession session = request.getSession();
ItemBean bean = new ItemBean();
bean.setProductID(results.getString("ProductID")); bean.setProductDescription(results.getString("ProductDescription")); bean.setProductName(results.getString("ProductName")); bean.setProductPrice(results.getString("ProductPrice"));
bean.setQuantity(Quantity);
ItemBeans item = (ItemBeans)session.getAttribute("basket");
item.addItemBean(bean);

This now works fine. But my next problem is trying use the information from the bean and storing it to the database. Do you guys know how it is done?

Is this how I will go about getting the details?

HttpSession session = request.getSession();
ItemBeans item = (ItemBeans)session.getAttribute("basket");

To get the product name do I do the following?
item.getProductName() or do I use the session attribute basket?

Basket is the id created in the jsp when using the bean.
 
Ranch Hand
Posts: 70
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Davendra Jesani
greenhorn
Member # 96380
posted April 15, 2005 07:36 AM
--------------------------------------------------------------------------------
Ive managed to add items to the basket using beans. This is the following code:

HttpSession session = request.getSession();
ItemBean bean = new ItemBean();
bean.setProductID(results.getString("ProductID")); bean.setProductDescription(results.getString("ProductDescription")); bean.setProductName(results.getString("ProductName")); bean.setProductPrice(results.getString("ProductPrice"));
bean.setQuantity(Quantity);
ItemBeans item = (ItemBeans)session.getAttribute("basket");
item.addItemBean(bean);

This now works fine. But my next problem is trying use the information from the bean and storing it to the database. Do you guys know how it is done?

Is this how I will go about getting the details?

HttpSession session = request.getSession();
ItemBeans item = (ItemBeans)session.getAttribute("basket");

To get the product name do I do the following?
item.getProductName() or do I use the session attribute basket?

Basket is the id created in the jsp when using the bean.


Hi Davendra ,

Are you using the type attribute in JSP(jsp:useBean)??
If yes, then it seems fine...

Regards,
 
Davendra Jesani
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I tried the method of accessing the bean in the servlet but it dont seem to work. It displays an error whenever I try to get an attribute name. For example, item.getProductName() does not work.


Do you know where I am going wrong?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

It displays an error


One place you are going wrong is trying to get help without giving the text of the error. Java error messages can be very informative.
If you are getting a NullPointerException message than one possibility is a difference in the way the parameter is spelled in the form versus the name you are trying to recover.
Bill
 
Neeraj Dheer
Ranch Hand
Posts: 225
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if you get a ClassnotFoundException for the bean, then here is one possible cause: for some reason, while using the jsp:useBean in JSPs, if the bean class is not part of a package, then the above exception is thrown.
For Ex:- If you have a bean class BeanClass.java in the $TOMCAT_HOME/webapps/<app>/WEB-INF/classes directory and try to access it using jsp:useBean, the above exception may be thrown.

If instead, you put BeaClass.java in a package, say Beans and now try using Beans.BeanClass, that should work.


I know this happens because i have spent too much time figuring it out and had found this issue mentioned somewhere on the internet, but i still dont know why. Can anyone enlighten me on this as well???
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Neeraj Dheer:

I know this happens because i have spent too much time figuring it out and had found this issue mentioned somewhere on the internet, but i still dont know why. Can anyone enlighten me on this as well???




Sun tightened things up a bit in the compiler, starting with J2SE1.4.

From:
http://java.sun.com/j2se/1.4/compatibility.html


The Javac bytecode compiler in J2SE 1.4.0 is more strict than in previous versions in enforcing compliance with the Java Language Specification. The new compiler may not compile existing code that does not strictly conform to the Java Language Specification, even though that code may have compiled with earlier versions of the compiler.

The following are some examples of situations in which the J2SE 1.4.0 compiler is stricter.

The compiler now rejects import statements that import a type from the unnamed namespace. Previous versions of the compiler would accept such import declarations, even though they were arguably not allowed by the language (because the type name appearing in the import clause is not in scope). The specification is being clarified to state clearly that you cannot have a simple name in an import statement, nor can you import from the unnamed namespace.

To summarize, the syntax
import SimpleName;
is no longer legal. Nor is the syntax
import ClassInUnnamedNamespace.Nested;

which would import a nested class from the unnamed namespace. To fix such problems in your code, move all of the classes from the unnamed namespace into a named namespace.


[ April 21, 2005: Message edited by: Ben Souther ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic