wood burning stoves 2.0*
The moose likes Java in General and the fly likes Cannot Resolve Symbol & my file uses or overrides deprecated API errors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Cannot Resolve Symbol & my file uses or overrides deprecated API errors " Watch "Cannot Resolve Symbol & my file uses or overrides deprecated API errors " New topic
Author

Cannot Resolve Symbol & my file uses or overrides deprecated API errors

Donna Harrington
Ranch Hand

Joined: Aug 08, 2003
Posts: 31
Hey everybody,
I hope somebody can help me.I am trying to create an online shopping cart that uses sessions. So i have a servlet side and a class Product and the client side 'ShopCart'. I have 2 errors..one is in the ShopCart.jsp file where it cannot resolve symbol 'class Product' and the other error is ShopCart.jsp uses or overrides deprecated API.
Here is ShopCart which is -->

<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@page import = "java.sql.*"%>
<%@page import = "java.io.*"%>
<%@page import = "java.util.Properties"%>
<%@page import = "java.io.InputStream"%>
<%@page session = "true"%>
<%@page import = "java.util.*"%>

<%
Vector buylist = (Vector) session.getValue("shopping.shoppingcart");
if (buylist != null && (buylist.size() > 0)) {
%>
<center>
<table border="0" cellpadding="0" width="100%" bgcolor="#FFFFFF">
<tr>
<td><b>ProductId</b></td>
<td><b>Product Name</b></td>
<td><b>Price</b></td>
<td><b>Quantity</b></td>
<td></td>
</tr>
<%
for (int index=0; index < buylist.size();index++) {
Product anOrder = (Product) buylist.elementAt(index);
%>
<tr>
<td><b><%= anOrder.getProductId() %></b></td>
<td><b><%= anOrder.getPName() %></b></td>
<td><b><%= anOrder.getPrice() %></b></td>
<td><b><%= anOrder.getQuantity() %></b></td>
<td>
<form name="deleteForm"
action="C:\Documents and Settings\HarringtonD\.netbeans\3.6\sampledir\WEB-INF\classes\com\mycompany\ShoppingServlet"
method="POST">
<input type="submit" value="Delete">
<input type="hidden" name= "delindex" value='<%= index %>'>
<input type="hidden" name="action" value="DELETE">
</form>
</td>
</tr>
<% } %>
</table>
<p>
<form name="checkoutForm"
action="C:\Documents and Settings\HarringtonD\.netbeans\3.6\sampledir\WEB-INF\classes\com\mycompany\ShoppingServlet"
method="POST">
<input type="hidden" name="action" value="CHECKOUT">
<input type="submit" name="Checkout" value="Checkout">
</form>
</center>
<% } %>

Here is my class Product -->

package shopping.Product;
public class Product {
String productId;
String PName;
float price;
int quantity;


/** Creates a new instance of Product */
public Product() {
productId="";
PName="";
price=0;
quantity=0;

}

public void setProductId(String title){
productId=title;
}
public String getProductId(){
return ProductId;
}
public String getPName(){
return PName;
}
public void setPrice(float p){
price=p;
}
public void setQuantity(){
return quantity;
}
}

And Finally Here is my Servlet -->

package shopping.Product;

import java.io.*;
import java.net.*;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;

/**
*
* @author HarringtonD
* @version
*/
public class ShoppingServlet extends HttpServlet {
public void init(ServletConfig conf) throws ServletException {
super.init(conf);
}
public void doPost (HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
HttpSession session = req.getSession(false);
if (session == null) {
res.sendRedirect("http://localhost:8084/sampledir/errorCart.html");
}
Vector buylist=
(Vector)session.getValue("shopping.shoppingcart");
String action = req.getParameter("action");
if (!action.equals("CHECKOUT")) {
if (action.equals("DELETE")) {
String del = req.getParameter("delindex");
int d = (new Integer(del)).intValue();
buylist.removeElementAt(d);
} else if (action.equals("ADD")) {
//any previous buys of same cd?
boolean match=false;
Product aProduct = getProduct(req);
if (buylist==null) {
//add first cd to the cart
buylist = new Vector(); //first order
buylist.addElement(aProduct);
} else { // not first buy
for (int i=0; i< buylist.size(); i++) {
Product prod = (Product) buylist.elementAt(i);
if (prod.getProductId().equals(aProduct.getProductId())) {
prod.setQuantity(prod.getQuantity()+aProduct.getQuantity());
buylist.setElementAt(prod,i);
match = true;
} //end of if name matches
} // end of for
if (!match)
buylist.addElement(aProduct);
}
}
session.putValue("shopping.shoppingcart", buylist);
String url="http://localhost:8084/sampledir/ShopCart.jsp";
ServletContext sc = getServletContext();
RequestDispatcher rd = sc.getRequestDispatcher(url);
rd.forward(req, res);
} else if (action.equals("CHECKOUT")) {
float total =0;
for (int i=0; i< buylist.size();i++) {
Product anOrder = (Product) buylist.elementAt(i);
float price= anOrder.getPrice();
int qty = anOrder.getQuantity();
total += (price * qty);
}
total += 0.005;
String amount = new Float(total).toString();
int n = amount.indexOf('.');
amount = amount.substring(0,n+3);
req.setAttribute("amount",amount);
String url="http://localhost:8084/sampledir/checkout.jsp";
ServletContext sc = getServletContext();
RequestDispatcher rd = sc.getRequestDispatcher(url);
rd.forward(req,res);
}
}
private Product getProduct(HttpServletRequest req) {
String myProduct = req.getParameter("Product");
String qty = req.getParameter("qty");
StringTokenizer t = new StringTokenizer(myProduct,"|");
String productId= t.nextToken();
String PName = t.nextToken();
String price = t.nextToken();
price = price.replace('$',' ').trim();
Product prod = new Product();
prod.setProductId(productId);
prod.setPName(PName);
prod.setPrice((new Float(price)).floatValue());
prod.setQuantity((new Integer(qty)).intValue());
return prod;
}
}


I hope somebody can help me., I cant see these erros..sorry about all the code. thanx.
Mike Nightsky
Ranch Hand

Joined: Aug 18, 2001
Posts: 48
in the jsp the package import for the java and the servlet is missing.
<%@page import ="shopping.Product.*"%>
this should solve your first problem.
the second one is just a warning, that means some parts of your code that you are using is marked as deprecated.
try to look in your log-files to see if you could find a clue.
If not try to compile the classes with -deprecation after javac, or if you use a IDE check if you could add this option in the settings.

Mike :roll:


Win the opportunity to make money on the Internet<br /><a href="http://sweeps.sitesell.com/minirich.html" target="_blank" rel="nofollow">http://sweeps.sitesell.com/minirich.html</a>
 
 
subject: Cannot Resolve Symbol & my file uses or overrides deprecated API errors
 
Similar Threads
Cannot Resolve Symbol & my file uses or overrides deprecated API errors
package does not exist
shopping cart prob
Problem with c:forEach Tag
shopping cart problem