加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
feiyong_servlet.java 3.66 KB
一键复制 编辑 原始数据 按行查看 历史
李世虎 提交于 2020-01-02 22:00 . 代码
package com.action;
import java.io.IOException;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.dao.DB;
import com.orm.TFeiyong;
public class feiyong_servlet extends HttpServlet
{
public void service(HttpServletRequest req,HttpServletResponse res)throws ServletException, IOException
{
String type=req.getParameter("type");
if(type.endsWith("feiyongMana"))
{
feiyongMana(req, res);
}
if(type.endsWith("feiyongList"))
{
feiyongList(req, res);
}
if(type.endsWith("feiyongAdd"))
{
feiyongAdd(req, res);
}
}
public void feiyongAdd(HttpServletRequest req,HttpServletResponse res)
{
String mingcheng=req.getParameter("mingcheng");
String shijian=req.getParameter("shijian");
String feiyong=req.getParameter("feiyong");
String leixing=req.getParameter("leixing");
String sql="insert into t_feiyong (mingcheng,shijian,feiyong,leixing) values(?,?,?,?)";
Object[] params={mingcheng,shijian,feiyong,leixing};
DB mydb=new DB();
mydb.doPstm(sql, params);
mydb.closed();
req.setAttribute("message", "ɹ");
req.setAttribute("path", "feiyong?type=feiyongMana");
String targetURL = "/common/success.jsp";
dispatch(targetURL, req, res);
}
public void feiyongMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
String sql="select * from t_feiyong";
req.setAttribute("feiyongList", getfeiyongList(sql));
req.getRequestDispatcher("admin/feiyong/feiyongMana.jsp").forward(req, res);
}
public void feiyongList(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException
{
String sql="select * from t_feiyong";
req.setAttribute("feiyongList", getfeiyongList(sql));
req.getRequestDispatcher("admin/feiyong/feiyongList.jsp").forward(req, res);
}
private List getfeiyongList(String sql)
{
List feiyongList=new ArrayList();
Object[] params={};
DB mydb=new DB();
try
{
mydb.doPstm(sql, params);
ResultSet rs=mydb.getRs();
while(rs.next())
{
TFeiyong feiyong=new TFeiyong();
feiyong.setId(rs.getInt("id"));
feiyong.setMingcheng(rs.getString("mingcheng"));
feiyong.setShijian(rs.getString("shijian"));
feiyong.setFeiyong(rs.getString("feiyong"));
int leixing = rs.getInt("leixing");
feiyong.setLeixing(getLxmc(leixing));
feiyongList.add(feiyong);
}
rs.close();
}
catch(Exception e)
{
e.printStackTrace();
}
mydb.closed();
return feiyongList;
}
private String getLxmc(int leixing)
{
String result = "";
switch(leixing)
{
case 0:
result = "";
break;
case 1:
result = "֧";
break;
case 2:
result = "";
break;
}
return result;
}
public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response)
{
RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI);
try
{
dispatch.forward(request, response);
return;
}
catch (ServletException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
}
public void init(ServletConfig config) throws ServletException
{
super.init(config);
}
public void destroy()
{
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化