創建user表
CREATE TABLE PTC.USERS
(
USERID VARCHAR2(30 BYTE),
USERNAME VARCHAR2(30 BYTE),
TRUENAME VARCHAR2(30 BYTE),
PASSWORD VARCHAR2(30 BYTE),
EMAIL VARCHAR2(50 BYTE),
PHONE VARCHAR2(30 BYTE),
ADDRESS VARCHAR2(100 BYTE),
POSTCODE INTEGER,
GRADE INTEGER
)
myCart.jsp
<%@ page language="java" import="java.util.*" pageEncoding="BIG5"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
購 物 流 程 - - >我 的 購 物 車 | |||||
編號 | 名稱 | 單价 | 數量 | 操作 | |
1 | 簡愛 | 25.0 | 刪除 | 查看 | |
login.jsp
<%@ page language="java" import="java.util.*" pageEncoding="BIG5"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
購 物 流 程 - - >用 戶 登 陸 | |||||||||||
| |||||||||||
GoodBeanDeal.java
添加下面的方法
//根據名稱搜索書籍信息
public GoodsBean getGoodsByName(String goodsName){
GoodsBean gb = null;
con = new ConnectDB().getConnectDB();
String sql = "select * from ptc.goods where goodsname='"+goodsName+"'";
try {
ps = con.prepareStatement(sql);
rs = ps.executeQuery(sql);
while(rs.next()){
gb = new GoodsBean();
gb.setGOODSID(rs.getInt(1));
gb.setGOODSNAME(rs.getString(2));
gb.setGOODSINTRO(rs.getString(3));
gb.setGOODSPRICE(rs.getFloat(4));
gb.setGOODSNUM(rs.getInt(5));
gb.setGOODSPUBLISHER(rs.getString(6));
gb.setPHOTONAME(rs.getString(7));
gb.setGOODSTYPE(rs.getString(8));
}
} catch (Exception e) {
e.printStackTrace();
}
return gb;
}
//Check用戶是否存在
public boolean CheckUsers(String userName,String password){
boolean checkResult=false;
ConnectDB cdb = new ConnectDB();
con = cdb.getConnection();
String sql = "select * from ptc.USER_INFORMATION where user_name='"+userName+"' and password='"+password+"'";
try {
sm = con.createStatement();
rs = sm.executeQuery(sql);
if(rs.next()){
checkResult=true;
}
} catch (SQLException e) {
e.printStackTrace();
}
return checkResult;
}
//用戶登陸判斷控制器
package com.wgf.controller;
import java.io.IOException;
import java.io.PrintWriter;
import com.ccc.wgf.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class UsersLogin extends HttpServlet {
/**
* The doGet method of the servlet.
*
* This method is called when a form. has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String userName = request.getParameter("userName");
userName = new String(userName.getBytes("iso-8859-1"));
String password =request.getParameter("password");
password = new String(password.getBytes("iso-8859-1"));
UserBeanDeal ubd = new UserBeanDeal();
if(ubd.CheckUsers(userName, password)){
request.getRequestDispatcher("FenYeDisplay?pageNow="+(1+"")).forward(request, response);
}
else{
request.getRequestDispatcher("login.jsp").forward(request, response);
}
}
/**
* The doPost method of the servlet.
*
* This method is called when a form. has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
}
ShowDetails控制器
package com.controller;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.wgf.*;
public class ShowDetail extends HttpServlet {
/**
* The doGet method of the servlet.
*
* This method is called when a form. has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String goodsName = request.getParameter("goodsName");
//System.out.println("goodsName ="+goodsName);
GoodsBean gb = new GoodsBean();
if(goodsName!=null){
gb = new GoodBeanDeal().getGoodsByName(goodsName);
}
request.setAttribute("goodsInformation", gb);
request.getRequestDispatcher("ShowDetails.jsp").forward(request, response);
}
/**
* The doPost method of the servlet.
*
* This method is called when a form. has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doGet(request, response);
}
}
ShowDetails.jsp
<%@ page language="java" import="java.util.*,com.wgf.*" pageEncoding="BIG5"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
function returnHall(){
form1.action ="index.jsp";
}
| |||||||||||||
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/22453766/viewspace-694634/ ,如需转载,请注明出处,否则将追究法律责任。