📄 servlet2.java
字号:
package mfkvit;
import java.lang.String;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import mfkvit.MD5_Test;
import mfkvit.JdbcBean;
import java.net.InetAddress;
//import com.sun.corba.se.internal.core.Request;
public class Servlet2 extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
public void init() throws ServletException {
}
//字符串处理
public String toString(String s) {
if (s == null) s = "";
try {
byte b[] = s.getBytes("ISO-8859-1");
s = new String(b);
} catch (Exception ex) {}
return s;
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String customer = toString(request.getParameter("customer"));
if (customer.equals("customerMessage"))
try {
customerMessage(request, response);
} catch (Exception ex) {}
if (customer.equals("RCZhaoping"))
try {
RCZhaoping(request, response);
} catch (Exception ex) {}
if (customer.equals("customerZhaoping"))
try {
customerZhaoping(request, response);
} catch (Exception ex) {}
if (customer.equals("delzhaoping"))
try {
delzhaoping(request, response);
} catch (Exception ex) {}
if (customer.equals("admin_cpxx"))
try {
cpxx(request, response);
} catch (Exception ex) {}
if (customer.equals("cpjjdel"))
try {
cpjjdel(request, response);
} catch (Exception ex) {}
if (customer.equals("hfcustomer"))
try {
hfcustomer(request, response);
} catch (Exception ex) {}
if (customer.equals("cpfw"))
try {
cpfw(request, response);
} catch (Exception ex) {}
if (customer.equals("wzgg"))
try {
wzgg(request, response);
} catch (Exception ex) {}
if (customer.equals("delwzgg"))
try {
delwzgg(request, response);
} catch (Exception ex) {}
if (customer.equals("addwzgg"))
try {
addwzgg(request, response);
} catch (Exception ex) {}
if (customer.equals("zczc"))
try {
zczc(request, response);
} catch (Exception ex) {}
if (customer.equals("gszz"))
try {
gszz(request, response);
} catch (Exception ex) {}
if (customer.equals("addcplb"))
try {
addcplb(request, response);
} catch (Exception ex) {}
if (customer.equals("delcplb"))
try {
delcplb(request, response);
} catch (Exception ex) {}
}
JdbcBean jdbc = new JdbcBean();
MD5_Test md5 = new MD5_Test();
private Object session;
//添加产品类别
public void addcplb(HttpServletRequest request,
HttpServletResponse response) throws
ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
String cplb = toString(request.getParameter("cplb"));
try {
String condition = " INSERT INTO cplb(cplb) VALUES" +
"('" + cplb + "')";
System.out.print(condition);
jdbc.execUpdate(condition);
InetAddress inet = InetAddress.getLocalHost();
//System.out.println("本机的ip=" + inet.getHostAddress());
out.println("<script languaga=\"JavaScript\">alert(\"添加成功!\");window.location = \"basic/admin/cplb.jsp\";</script>");
} catch (Exception ex) {
ex.printStackTrace();
out.print("<script>alert(' 添加失败!')</script>");
out.print("<script>history.back(-1)</script>"); //返回原来页面
}
}
//删除产品类别
public void delcplb(HttpServletRequest request,
HttpServletResponse response) throws
ServletException, IOException {
String[] sc = request.getParameterValues("sc");
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
try {
if (sc != null) {
for (int i = 0; i < sc.length; i++) {
String condition = "delete from cplb where id=" +
sc[i];
System.out.print(condition);
jdbc.execUpdate(condition);
}
out.println("<script languaga=\"JavaScript\">alert(\"删除成功!\");window.location = \"basic/admin/cplb.jsp\";</script>");
}
} catch (Exception ex) {
ex.printStackTrace();
}
out.print("<script>alert(' 删除失败!')</script>");
out.print("<script>history.back(-1)</script>"); //返回原来页面
}
//添加产品名称
public void cpxx(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
String cpmc = toString(request.getParameter("cpmc"));
String cplb = toString(request.getParameter("cplb"));
String cpgg = toString(request.getParameter("cpgg"));
String bz = toString(request.getParameter("bz"));
String cpjj = new String(request.getParameter("content1").getBytes(
"iso8859_1"));
String img = toString(request.getParameter("img"));
//img="../img/img/company.gif";
System.out.print(img);
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
try {
String condition =
" INSERT INTO CPmessage(cpmc,cpgg,cpjj,img,cplb,bz) VALUES" +
"(" + "'" + cpmc + "','" + cpgg + "','" +
cpjj + "','" + img + "','" +cplb+"','"+ bz + "')";
System.out.print(condition);
jdbc.execUpdate(condition);
out.println("<script languaga=\"JavaScript\">alert(\" 产品添加成功!\");window.location = \"basic/admin/cpxx.jsp\";</script>");
} catch (Exception ex) {
ex.printStackTrace();
out.print("<script>alert(' 添加失败!')</script>");
out.print("<script>history.back(-1)</script>"); //返回原来页面
}
}
//删除产品
public void cpjjdel(HttpServletRequest request,
HttpServletResponse response) throws
ServletException, IOException {
String[] sc = request.getParameterValues("sc");
String name;
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
try {
if (sc != null) {
for (int i = 0; i < sc.length; i++) {
String condition = "delete from CPmessage where id=" +
sc[i];
request.setCharacterEncoding("gb2312");
String lb = request.getParameter("lb");
try {
int rowcount = jdbc.execQueryName(
"select * from CPmessage where id=" + sc[i]);
ArrayList al = jdbc.getRS();
for (int t = 0; t < rowcount; t++) {
HashMap colValue = (HashMap) al.get(i);
name = (String) colValue.get("img");
String img = name.substring(18);
String filepath = getServletContext().getRealPath(
"") + "/ShangChuangImg/" + img;
File file1 = new File(filepath); //删除文件
try {
file1.delete();
} catch (Exception e) {}
System.out.print(filepath);
}
} catch (Exception ex) {
ex.printStackTrace();
}
System.out.print(condition);
jdbc.execUpdate(condition);
}
out.println("<script languaga=\"JavaScript\">alert(\"产品删除成功!\");window.location = \"basic/admin/seecpxx.jsp\";</script>");
out.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
out.print("<script>alert(' 删除失败!')</script>");
out.print("<script>history.back(-1)</script>"); //返回原来页面
}
//产品服务
public void cpfw(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException, SQLException {
String nr = new String(request.getParameter("content1").getBytes(
"iso8859_1"));
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
try {
String condition = "update cpfw set nr='" + nr+"'";
System.out.print(condition);
jdbc.execUpdate(condition);
out.println("<script languaga=\"JavaScript\">alert(\"更新成功!\");window.location = \"basic/admin/cpfw.jsp\";</script>");
} catch (Exception ex) {
ex.printStackTrace();
out.print("<script>alert(' 更新失败!输入不能为空')</script>");
out.print("<script>history.back(-1)</script>"); //返回原来页面
}
}
//回复顾客留言
public void hfcustomer(HttpServletRequest request,
HttpServletResponse response) throws
ServletException, IOException {
String id = toString(request.getParameter("hf"));
String hf = toString(request.getParameter("hfcustomer"));
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -