JAVA 基础例题包含了JAVA常见的问题和常见的习题

源代码在线查看: dummycart.java

软件大小: 4510 K
上传用户: cocoplus
关键词: JAVA
下载地址: 免注册下载 普通下载 VIP

相关代码

				import javax.servlet.http.*;
				import javax.servlet.*;
				import java.util.*;
				public class DummyCart
				{
					Vector v = new Vector();
					String submit = null;
					String item = null;
					private void addItem(String name)
					{
					 v.addElement(name);
					}
					private void removeItem(String name)
					{
						v.removeElement(name);
					}
					public void setItem(String name)
					{
						item = name;
					}
					public void setSubmit(String s)
					{
						submit = s;
					}
					public String[] getItems()
					{
						String[] s = new String[v.size()];
						v.copyInto(s);
						return s;
					}
					
					public void processRequest(HttpServletRequest request)
					{
						//判断submit的值
						submit = (String)request.getParameter("submit");
					//	System.out.println(submit);
						item = (String)request.getParameter("item");
						if(submit.equals("null"))
						 addItem(item);
						if(submit.equals("add"))
						  addItem(item);
						else if(submit.equals("remove"))
						  removeItem(item);
						// 重置submit的值
						reset();
					}
					
					private void reset()
					{
						submit = null;
						item = null;
				  }
				}			

相关资源