jsp的技术教程

源代码在线查看: shopcart.jsp

软件大小: 698 K
上传用户: srbrabbit
关键词: jsp 技术教程
下载地址: 免注册下载 普通下载 VIP

相关代码

				
				
				
								if(session.getAttribute("username")==null||session.getAttribute("username")=="")
				{
					response.sendRedirect("../member/login.jsp?url="+request.getRequestURI());
				}
				
				
				%>
								public String getStr(String str)
				{
					try
					{
						String temp_p=str;
						byte[] temp_t=temp_p.getBytes("GBK");
						String temp=new String(temp_t,"ISO8859_1");
						return temp;
					}
					catch(Exception e)
					{
					 
					}
					return "null";
				}
				%>        
				
								String book_id=request.getParameter("book_id");
				//是否已经选择该货物
				    String sql="select ID from orders where book_id="+book_id+" and user_name='"+session.getAttribute("username")+"' and status=0";
					ResultSet RS=workM.executeQuery(sql);
					//out.println(sql);
					int rowscount=0;
					try
					{
						while(RS.next())
						{
							rowscount++;
						}
					}
					catch(Exception e)
					{
				
					}
				//把货物放入购物车
				
				//out.println(rowscount==0);
				if(rowscount==0)
				{
						String sqlBook1="select book.* from book where id="+book_id;
						ResultSet RSBook1=workM.executeQuery(sqlBook1);
						while(RSBook1.next())
						{
							String sqlCart="insert into  orders(user_name,book_id,book_number,status,goods_price)  Values('"+session.getAttribute("username")+"','"+book_id+"','1','0','"+RSBook1.getDouble("price")+"')";
							//out.println(sqlCart);
							workM.executeQuery(sqlCart);
						}
				}
				else
				{
						String sqlBook2="select book.* from book where id="+book_id;
						ResultSet RSBook2=workM.executeQuery(sqlBook2);
						while(RSBook2.next())
						{
							String sqlAdd="update orders set book_number=book_number+1,goods_price="+RSBook2.getDouble("price")+" where book_id="+book_id+" and user_name='"+session.getAttribute("username")+"' and status=0";
							//out.println(sqlAdd);
							workM.executeQuery(sqlAdd);
						}
				}
				 /*
						int count; 
						count=0;
						
					  	String sqlBook3="select * from price where user_name="+session.getAttribute("username");
						ResultSet RSBook3=workM.executeQuery(sqlBook3);
						while(RSBook3.next())
						{
							count=count+1;
					 	}
						if(count==0)
						{	
							String sqlBook4="select * from orders where user_name="+session.getAttribute("username");
							ResultSet RSBook4=workM.executeQuery(sqlBook4);
							while(RSBook4.next())
							{
							String sqlPrice="insert into price(user_name,goods_price,total_price) values('"+session.getAttribute("username")+"','"+(double)(RSBook4.getDouble("goods_price")*RSBook4.getInt("book_number"))+"','goods_price+5')";		
							workM.executeQuery(sqlPrice);		
							}
						}
						else
						{	
							String sqlBook5="select * from orders where user_name="+session.getAttribute("username");
							ResultSet RSBook5=workM.executeQuery(sqlBook5);
							while(RSBook5.next())
							{
							String sqlPrice="update price set goods_price="+(double)(RSBook5.getDouble("goods_price")*RSBook5.getInt("book_number"))+",total_price=goods_price+5";		
							workM.executeQuery(sqlPrice);	
							}		
						}*/
				response.sendRedirect("cart.jsp");
				%>                
				
				
				[详细资料]
				
				
				
				
				
				
				  
				    
				      
				        购 物 车 
				      
				    
				  
				  
				  您的购物车中包含以下货物:
				  
				     
				       
				        购买数量
				      
				       
				        书名
				      
				       
				        单价
				      
				       
				        总价格
				      
				    
										String sqlList="select * from orders where user_name='"+session.getAttribute("username")+"' and status=0";
					ResultSet RSList=workM.executeQuery(sqlList);
					try
					{
						while(RSList.next())
						{
							int b_num;
							b_num=RSList.getInt("book_number");
					%>
				     
				       
				          
				          
				          
				      
					  					  	String sqlBook="select book.* from book where id="+RSList.getInt("book_id");
						ResultSet RSBook=workM.executeQuery(sqlBook);
						while(RSBook.next())
						{
							
					  %>
				       
				        
				      
				       
					  					  	double price;
						price=RSBook.getDouble("price");
					  %>
				        元
				      
					 
				       
				        ¥元
				      
					   
				    
				     
				       
				        货物价格
				      
				       
				        ¥
				      
				    
											}
					}
					catch(Exception e)
					{
					}
					%>
				     
				        
				         
				        运输费用
				      
				       
				        ¥
				      
				    
				     
				       
				        总费用
				      
				       
				        ¥
				      
				    
					  
				       
					 
				    
				    
				    
				  
				  
				    
				  
				   
				
				
				
				
							

相关资源