This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes JSP and the fly likes How to set the classpath in JSP page@ page session= Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to set the classpath in JSP page@ page session="true" import="java.util.*,java.io" Watch "How to set the classpath in JSP page@ page session="true" import="java.util.*,java.io" New topic
Author

How to set the classpath in JSP page@ page session="true" import="java.util.*,java.io

sethuramanrajapalayam raman
Greenhorn

Joined: Feb 14, 2003
Posts: 1
Respected sir,
I have write one java program,servlet program and jsp program .
Java program is nothing but a package which are presented inside the after servlets folder.
<c:\javawebserver2.0\servlets\displaycart>
where
c:\javawebserver2.0\servlets : servlet files are stored here.
package stored in
<c:\javawebserver2.0\servlets\displaycart>
package name is..cartItem.java
jsp files are in
c:\javawebserver2.0\public_html\sethu
orderpage_hcl.jsp
------------------
servlet file:
------------
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import displaycart.cartItem;
public class cartpage extends HttpServlet
{
public void init(ServletConfig conf) throws ServletException
{
super.init(conf);
} // End of the Init function
public void doPost(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
HttpSession session=req.getSession(true);
String sid;
Vector cart_list =(Vector)session.getValue("SESSION_CART_DATA");
String action=req.getParameter("action");
sid=session.getId();
boolean match=false;
if(action.equals("add"))
{
cart_list=new Vector();
cartItem c=getItems(req); // create new object
if(cart_list==null)
{
cart_list=new Vector();
cart_list.addElement(c); //assign the object variable
}
else
{
for(int i=0;i<cart_list.size();i++)
{
cartItem c1=(cartItem) cart_list.elementAt(i);
if(c1.getProductId().equals(c.getProductId()))
{
c1.setProductQty(c1.getProductQty()+c.getProductQty());
cart_list.setElementAt(c1,i);
match=true;
} // If Qty matches
} // End for
if(!match)
cart_list.addElement(c); //assign the object variable
} // else
} // if

session.putValue("SESSION_CART_DATA",cart_list);
ServletContext sc=getServletContext();
String url="http://localhost:8080/sethu/shoppingbag.jsp";
RequestDispatcher rd=sc.getRequestDispatcher(url);
rd.forward(req,res);

}// End of the doPost Function

public cartItem getItems(HttpServletRequest req) throws ServletException,IOException
{
String p_name,p_id,p_qty;
String p_amount;
p_id=req.getParameter("product_id");
p_name=req.getParameter("product_name");
p_qty =req.getParameter("quantity");
p_amount=req.getParameter("amount");
cartItem cItem=new cartItem();
cItem.setProductName(p_name);
cItem.setProductId(p_id);
cItem.setProductQty((new Integer(p_qty)).intValue());
cItem.setProductAmount((new Float(p_amount)).floatValue());
return cItem;
}// end with Getitems function
} //End of the Cart class
package file.
============
package displaycart;
public class cartItem
{
String product_id;
String product_name;
int qty;
String rate;
float amount;
public void setProductId(String id)
{
product_id=id;
}
public String getProductId()
{
return product_id;
}

public void setProductName(String p_name)
{
product_name=p_name;
}
public String getProductName()
{
return product_name;
}
public void setProductQty(int product_qty)
{
qty=product_qty;
}
public int getProductQty()
{
return qty;
}
/*public void setProductRate(String product_rate)
{
rate=product_rate;
}
public String getProductRate()
{
return rate;
}*/
public void setProductAmount(float product_amount)
{
amount=product_amount;
}
public float getProductAmount()
{
return amount;
}
}
output jsp file<shoppingbag.jsp>
===============
<%==========================
Error getting compiled page
C:\JAVAWEBSERVER2.0\BIN\..\tmpdir\default\pagecompile\jsp\_sethu\_shoppingbag.java:13: Class displaycart.cartItem not found in import.
import displaycart.cartItem;;
^
1 error

pls clear my doubt quickly.
nishwas mahindra
Ranch Hand

Joined: Dec 23, 2002
Posts: 104
you have to set your machines classpath to get yor package.
I dont know about javawebserver...but there must be WEB-INF directory where you can put your classes and packages which are directly available thru' your jsp's.
[ February 19, 2003: Message edited by: bipin deshpande ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to set the classpath in JSP page@ page session="true" import="java.util.*,java.io