81,092
社区成员
发帖
与我相关
我的任务
分享
package ser;
import impl.AccountImpl;
import it.shopping.dao.IAccount;
import it.shopping.pojo.Account;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class AccountSer extends HttpServlet
{
private IAccount accountImpl = new AccountImpl();
private static final long serialVersionUID = -3708568559174453120L;
public AccountSer()
{
super();
}
public void destroy()
{
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
this.doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String status = request.getParameter("status");
if(status.equals("login"))
{
Account account = new Account();
account.setAlogin(request.getParameter("alogin"));
account.setApass(request.getParameter("apass"));
account =accountImpl.queryAccount(account);
if(account == null)
{
request.setAttribute("error", "登录失败");
request.getRequestDispatcher("/alogin.jsp").forward(request, response);
// response.sendRedirect("alogin.jsp");
}
{
request.getSession().setAttribute("account", account);
// response.sendRedirect("/t31/admin/index.jsp");
// 重定向和请求装啊session值都不会失效!
request.getRequestDispatcher("/admin/index.jsp").forward(request, response);
}
}
}
public void init() throws ServletException
{
// Put your code here
}
}
package ser;
import impl.CategoryImpl;
import it.shopping.dao.ICategory;
import it.shopping.pojo.Account;
import it.shopping.pojo.Category;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class CategorySer extends HttpServlet
{
private ICategory categoryImpl = new CategoryImpl();
public void destroy()
{
super.destroy();
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
this.doPost(req,resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
{
String status = req.getParameter("status");
if(status.equals("savaCategory"));
{
Category category = new Category();
category.setCtype(req.getParameter("ctype"));
category.setChot(Boolean.parseBoolean(req.getParameter("chot")));
category.setAccount((Account) req.getSession().getAttribute("account"));
System.out.println(category.getAccount());
categoryImpl.queryCategory(category);
resp.sendRedirect("/t31/admin/main.jsp");
}
}
public void init() throws ServletException
{
}
}
package it.shopping.pojo;
public class Account
{
private int aid;
private String alogin;
private String apass;
public int getAid()
{
return aid;
}
public void setAid(int aid)
{
this.aid = aid;
}
public String getAlogin()
{
return alogin;
}
public void setAlogin(String alogin)
{
this.alogin = alogin;
}
public String getApass()
{
return apass;
}
public void setApass(String apass)
{
this.apass = apass;
}
}
package it.shopping.pojo;
public class Category
{
private int cid;
private String ctype;
private Boolean chot;
private Account account;
public int getCid()
{
return cid;
}
public void setCid(int cid)
{
this.cid = cid;
}
public String getCtype()
{
return ctype;
}
public void setCtype(String ctype)
{
this.ctype = ctype;
}
public Boolean getChot()
{
return chot;
}
public void setChot(Boolean chot)
{
this.chot = chot;
}
public Account getAccount()
{
return account;
}
public void setAccount(Account account)
{
this.account = account;
}
}
package impl;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import utils.JdbcUtils;
import it.shopping.dao.ICategory;
import it.shopping.pojo.Category;
public class CategoryImpl implements ICategory
{
@Override
public Category queryCategory(Category category)
{
Connection conn = null;
PreparedStatement pre = null;
String sql =" INSERT INTO category {?,?,?}";
ResultSet rs = null;
try
{
System.out.println("hello3.0");
conn = JdbcUtils.getConnection();
pre = conn.prepareStatement(sql);
System.out.println("hello4.0");
System.out.println(category.getAccount().getAid());
pre.setInt(1,category.getAccount().getAid());
pre.setString(2, category.getCtype());
pre.setBoolean(3,category.getChot());
System.out.println("hello6.0");
pre.executeQuery();
} catch (SQLException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}finally
{
JdbcUtils.free(rs, pre, conn);
}
return category;
}
}