001 | package com.action; |
002 |
003 | import java.io.IOException; |
004 | import java.sql.ResultSet; |
005 | import java.util.ArrayList; |
006 | import java.util.List; |
007 |
008 | import javax.servlet.RequestDispatcher; |
009 | import javax.servlet.ServletConfig; |
010 | import javax.servlet.ServletException; |
011 | import javax.servlet.http.HttpServlet; |
012 | import javax.servlet.http.HttpServletRequest; |
013 | import javax.servlet.http.HttpServletResponse; |
014 |
015 | import com.dao.DB; |
016 | import com.orm.Ttea; |
017 |
018 | public class tea_servlet extends HttpServlet |
019 | { |
020 | @Override |
021 | public void service(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException |
022 | { |
023 | String type=req.getParameter( "type" ); |
024 | |
025 | if (type.endsWith( "teaAdd" )) |
026 | { |
027 | teaAdd(req, res); |
028 | } |
029 | if (type.endsWith( "teaDel" )) |
030 | { |
031 | teaDel(req, res); |
032 | } |
033 | if (type.endsWith( "teaMana" )) |
034 | { |
035 | teaMana(req, res); |
036 | } |
037 | |
038 | if (type.endsWith( "teaAll" )) |
039 | { |
040 | teaAll(req, res); |
041 | } |
042 | } |
043 | |
044 | |
045 | public void teaAdd(HttpServletRequest req,HttpServletResponse res) |
046 | { |
047 | String bianhao=req.getParameter( "bianhao" ); |
048 | String name=req.getParameter( "name" ); |
049 | String sex=req.getParameter( "sex" ); |
050 | String age=req.getParameter( "age" ); |
051 | |
052 | String loginname=req.getParameter( "loginname" ); |
053 | String loginpw=req.getParameter( "loginpw" ); |
054 | String del= "no" ; |
055 | String id= null ; |
056 | |
057 | |
058 | String sql= "insert into t_tea(bianhao,name,sex,age,loginname,loginpw,del) values(?,?,?,?,?,?,?)" ; |
059 | Object[] params={bianhao,name,sex,age,loginname,loginpw,del}; |
060 | DB mydb= new DB(); |
061 | mydb.doPstm(sql, params); |
062 | mydb.closed(); |
063 | |
064 | req.setAttribute( "message" , "²Ù×÷³É¹¦" ); |
065 | req.setAttribute( "path" , "tea?type=teaMana" ); |
066 | |
067 | String targetURL = "/common/success.jsp" ; |
068 | dispatch(targetURL, req, res); |
069 | } |
070 | |
071 | public void teaDel(HttpServletRequest req,HttpServletResponse res) |
072 | { |
073 | String sql= "update t_tea set del='yes' where id=" +Integer.parseInt(req.getParameter( "id" )); |
074 | Object[] params={}; |
075 | DB mydb= new DB(); |
076 | mydb.doPstm(sql, params); |
077 | mydb.closed(); |
078 | |
079 | req.setAttribute( "message" , "²Ù×÷³É¹¦" ); |
080 | req.setAttribute( "path" , "tea?type=teaMana" ); |
081 | |
082 | String targetURL = "/common/success.jsp" ; |
083 | dispatch(targetURL, req, res); |
084 | } |
085 |
086 | public void teaMana(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException |
087 | { |
088 | List teaList= new ArrayList(); |
089 | String sql= "select * from t_tea where del='no'" ; |
090 | Object[] params={}; |
091 | DB mydb= new DB(); |
092 | try |
093 | { |
094 | mydb.doPstm(sql, params); |
095 | ResultSet rs=mydb.getRs(); |
096 | while (rs.next()) |
097 | { |
098 | Ttea tea= new Ttea(); |
099 | |
100 | tea.setId(rs.getInt( "id" )); |
101 | tea.setBianhao(rs.getString( "bianhao" )); |
102 | tea.setName(rs.getString( "name" )); |
103 | tea.setSex(rs.getString( "sex" )); |
104 | |
105 | tea.setAge(rs.getString( "age" )); |
106 | tea.setLoginname(rs.getString( "loginname" )); |
107 | tea.setLoginpw(rs.getString( "loginpw" )); |
108 | tea.setDel(rs.getString( "del" )); |
109 | |
110 | teaList.add(tea); |
111 | } |
112 | rs.close(); |
113 | } |
114 | catch (Exception e) |
115 | { |
116 | e.printStackTrace(); |
117 | } |
118 | mydb.closed(); |
119 | |
120 | req.setAttribute( "teaList" , teaList); |
121 | req.getRequestDispatcher( "admin/tea/teaMana.jsp" ).forward(req, res); |
122 | } |
123 | |
124 | public void teaAll(HttpServletRequest req,HttpServletResponse res) throws ServletException, IOException |
125 | { |
126 | List teaList= new ArrayList(); |
127 | String sql= "select * from t_tea where del='no'" ; |
128 | Object[] params={}; |
129 | DB mydb= new DB(); |
130 | try |
131 | { |
132 | mydb.doPstm(sql, params); |
133 | ResultSet rs=mydb.getRs(); |
134 | while (rs.next()) |
135 | { |
136 | Ttea tea= new Ttea(); |
137 | |
138 | tea.setId(rs.getInt( "id" )); |
139 | tea.setBianhao(rs.getString( "bianhao" )); |
140 | tea.setName(rs.getString( "name" )); |
141 | tea.setSex(rs.getString( "sex" )); |
142 | |
143 | tea.setAge(rs.getString( "age" )); |
144 | tea.setLoginname(rs.getString( "loginname" )); |
145 | tea.setLoginpw(rs.getString( "loginpw" )); |
146 | tea.setDel(rs.getString( "del" )); |
147 | |
148 | teaList.add(tea); |
149 | } |
150 | rs.close(); |
151 | } |
152 | catch (Exception e) |
153 | { |
154 | e.printStackTrace(); |
155 | } |
156 | mydb.closed(); |
157 | |
158 | req.setAttribute( "teaList" , teaList); |
159 | req.getRequestDispatcher( "qiantai/tea/teaAll.jsp" ).forward(req, res); |
160 | } |
161 | |
162 | |
163 | public void dispatch(String targetURI,HttpServletRequest request,HttpServletResponse response) |
164 | { |
165 | RequestDispatcher dispatch = getServletContext().getRequestDispatcher(targetURI); |
166 | try |
167 | { |
168 | dispatch.forward(request, response); |
169 | return ; |
170 | } |
171 | catch (ServletException e) |
172 | { |
173 | e.printStackTrace(); |
174 | } |
175 | catch (IOException e) |
176 | { |
177 | |
178 | e.printStackTrace(); |
179 | } |
180 | } |
181 | @Override |
182 | public void init(ServletConfig config) throws ServletException |
183 | { |
184 | super .init(config); |
185 | } |
186 | |
187 | @Override |
188 | public void destroy() |
189 | { |
190 | |
191 | } |
192 | } |

你爹正在加载中 LV4
2023年7月19日
ZDM133 LV2
2023年5月22日
wangdongtai LV31
2022年5月20日
ll23344y LV2
2022年2月15日
夜星1111 LV1
2022年1月6日
hshhshh LV1
2021年12月26日
Start1 LV15
2021年11月25日
ssssha LV1
2021年7月6日
ericxu1116 LV24
2021年6月28日
Rovann LV1
2021年6月20日

329512801 LV28
3月24日
15719908287 LV9
2024年12月3日
微信网友_7041475584184320
2024年6月17日
暂无贡献等级
微信网友_6906962132258816 LV7
2024年5月15日
zayuchuan
2024年1月3日
暂无贡献等级
asddwh LV13
2023年12月26日
hanzhuohong LV1
2023年12月25日
komorebi123987 LV5
2023年12月9日
小芳同学 LV1
2023年12月5日
去码头整点薯条 LV3
2023年11月15日