This week's giveaway is in the Beginning Java forum.
We're giving away four copies of Bad Programming Practices 101 (e-book) and have Karl Beecher on-line!
See this thread for details.
Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!

Santhini Nesaraj

Greenhorn
+ Follow
since May 16, 2005
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Santhini Nesaraj

Thanks a lot. It works.
12 years ago
I am a beginner in Java. I have a String as below:

public class Name {
public static void main(String[] args) {

String s = "John Doe";
String s1 = "Jane White";
System.out.println();

}
}
Now I want to print First name and last name seperately. How do I do this? I know I can write code as s.substring(0,4) or vice versa. But if you have a list of names you cant go about writing (0,3) or (0,5) simultaneously. You can seperate the FirstName and LastName from its space. How do you do that? Please help!

Thanks.
12 years ago
I am a beginner in XML. I have an XML file like this:

<catalog>

<book id="101">
<title>XMLInANutshell</title>
<author>ElliotteRustyHarold</author>
<price>39.95</price>
</book>

<book id="121">
<title>WhoMovedMyCheese</title>
<author>SpencerJohnsonKennethBlanchard</author>
<price>19.95</price>
</book>
</catalog>

USing Java code how can I parse the XML file with Dom parser and display all entries. Please could some write the code for me? It would be very helpful. Thanks.
import java.util.ArrayList;
import java.util.Hashtable;

public class Information {
public static void main(String[] args) {
ArrayList al[]= new ArrayList[2];
al[0]=

(i am stuck over here)

}
}
how do i add the values (empname, empid,empsalary ) to it.
I have refferred a lot of books and sites nothing helps. I want the exact answer for it.
13 years ago
This is the requirement that I have got that I posted I have no idea how to start it.
Insert the values into the hashtable and retrieve them thro loop.
This is what I have done so far:

import java.util.ArrayList;
import java.util.Hashtable;

public class Information {
public static void main(String[] args) {
ArrayList al[]= new ArrayList[2];

I dont know how to add the values to it. The arraylist has to be converted to hashtable it seems and retieve the value thro loop.
13 years ago
I want to create a Hashtable and add values for eg.(empname,empid,empsalary) to it and retrieve the values by looping
(for loop). It would be great if someone could give me the solution to this problem really soon because I have been working on it for two days. Links Tutorials and books does not help.

Thanks in advance!!
13 years ago
I need to create a hashtable and put the values for eg.(empname,dateofappointment,empid,empsalary) in it. And retrieve the values using for loop. How can I do it? Can someone give me the solution for this? Please ,I am a dummy in Java.
13 years ago
I am a beginner to Java. I am doing an assignment of a Shopping cart application. Below is the action class I have created. I want a number to display in the JSP page each time the size of the array increases. How do I call the arraylist from the servlet in the JSP page? Any help would be greatly appreciated. Thank You.

public class ItemAddToCartAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

HttpSession session = request.getSession();
try {
Hashtable item = new Hashtable();
item.put("brand", request.getParameter("brand"));
item.put("color", request.getParameter("color"));
item.put("size", request.getParameter("size"));
item.put("price", request.getParameter("price"));
item.put("shipping", request.getParameter("shipping"));
if (session.getAttribute("cart") == null) {
ArrayList cart = new ArrayList();
cart.add(item);
session.setAttribute("cart", cart);
}

else {
ArrayList cartFromSession = (ArrayList)
session.getAttribute("cart");
cartFromSession.add(item);
session.setAttribute("cart",cartFromSession);
}

} catch (Exception e) {
System.out.println("Exception occured");
return mapping.findForward("Failure");
}
return mapping.findForward("SUCCESS");

}
}
13 years ago
Hi,

I am a Java begininer. I am doing an assignment on shopping cart using Struts framework. so I created an ArrayList in the action class. This is to add the items to the cart. But there is some error in the arraylist which I coudlnt fix. And I need to create a JSP file that will indicate that how many items are added to the cart each time an item is selected, How do I do that using JSP ? Need a quick reply.

Here I have pasted the code of the action class I created . It shows some error on this code. I couldnt fix it:

public class ItemAddToCartAction extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

HttpSession session = request.getSession();
try{
if(session.getAttribute("cart")== null){
ArrayList cart= new ArrayList();
Hashtable item= new Hashtable();
item.put("brand",cart);
item.put("color",cart);
item.put("size",cart);
item.put("price",cart);
item.put("shipping",cart);
cart.add(item);
session.setAttribute("cart",cart);
}

else (session.getAttribute("cart",cart)){
ArrayList cart=(ArrayList)session.getAttribute("cart");
}

Please give me a solution to fix the error for the action class and also how to create the JSP file. Any help would be greatly appreciated.

Thanks!
13 years ago