代码拉取完成,页面将自动刷新
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()
{
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。