wareselectservlet.java
来自「本系统是一个具有交互功能的C2C类型的电子商务网站(客户与客户之间进行商品交易的」· Java 代码 · 共 76 行
JAVA
76 行
package myservlet.s;
import mybean.b.*;
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class WareSelectServlet extends HttpServlet{
public void init(ServletConfig config) throws ServletException{
super.init(config);
try{
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
}catch(Exception e){}
}
public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
Connection con;
Statement sql;
StringBuffer str=new StringBuffer();
HttpSession session=request.getSession(true);
ChaxunBean chaxunbean=new ChaxunBean();
request.setAttribute("chaxunbean",chaxunbean);
String ssortname=request.getParameter("sortname");
byte b[]=ssortname.getBytes("ISO-8859-1");
ssortname=new String(b);
String swarename=request.getParameter("warename");
byte c[]=swarename.getBytes("ISO-8859-1");
swarename=new String(c);
try{
con=DriverManager.getConnection("jdbc:sqlserver://127.0.0.1:1433;DatabaseName=shopping","shop","123");
sql=con.createStatement();
ResultSet rs;
String str1="select WareName,Company,Price,WareID from wares where WareName='"+swarename+"' and SortName='"+ssortname+"'";
rs=sql.executeQuery(str1);
if(rs.next()){
str.append("<table border=1 bordercolor=#FFFF00 bgcolor=#66CCFF>");
str.append("<tr>");
str.append("<td width=170 height=44 align=center>商品名称</td>");
str.append("<td width=110 align=center>生产厂家</td>");
str.append("<td width=110 align=center>商品价格</td>");
str.append("<td width=130 align=center>查看商品信息</td>");
str.append("</tr>");
while(rs.next()){
str.append("<tr>");
str.append("<th align=center>"+rs.getString(1)+"</th>");
str.append("<th align=center>"+rs.getString(2)+"</th>");
str.append("<th align=center>"+rs.getString(3)+"元</th>");
str.append("<th align=center><form action=lookpreparebuyservlet method=post><input type=submit value=查看><input type=hidden name=wareid value="+rs.getString(4)+"></form></th>");
str.append("</tr>");
}
str.append("</table>");
}
else{
response.sendRedirect("b.jsp");
}
chaxunbean.setResult(str);
con.close();
}
catch(Exception e)
{str.append(""+e);chaxunbean.setResult(str);}
RequestDispatcher dispatcher=request.getRequestDispatcher("selectresult.jsp");
dispatcher.forward(request,response);
}
public void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException{
doPost(request,response);
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?