search.jsp页面输出好像是地址不是数据,困扰我很久了一直没找到答案。。

a8669256 2010-05-29 02:24:46
我页面ss.jsp代码
<%@page contentType="text/html;charset=GB2312" %>
<html>
<head>
<title>商家搜索</title>

</style>
</head>

<body>
<form name="form1" onsubmit="return check()" method="post" action="<%=request.getContextPath()%>/servlet/com.wjxl.Servlet.sjServlet?method=search">
<table width="80%" border="1" align="center" bgcolor="#0099FF">
<tr bgcolor="#FFFFFF">
<th height="39" scope="row"><div align="left">
<span style="font-weight: 400"><font size="2">查询项目:</font></span></div></th>
<td><select name="item" size=1>
<option value="">请选择</option>
<option value="sj_addr">商家地址</option>
<option value="sj_bh">商家编号</option>
<option value="sj_name">商家名称</option>
</select>
</td>
<td><font size="2">查询内容:</font></td>
<td><input type="text" name="content"></td>
<td><input type="submit" name="submit" value="查询">
</tr>
</table>
</form>
</body>
</html>
<script type="text/javascript">
function check()
{
if (form1.content.value=="")
{
alert("请输入查询内容!");
form1.content.focus();
return false;
}
}
</script>
Servlet代码:
package com.wjxl.Servlet;
import java.io.*;
import java.util.Vector;
import javax.servlet.*;
import javax.servlet.http.*;
import com.wjxl.Dao.sjDaoImp;
import com.wjxl.Dao.sjInfo;
public class sjServlet extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException{
resp.sendRedirect(req.getContextPath()+"/user/login.jsp");
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException{

String method = req.getParameter("method");
String forward = null;
if (method.equalsIgnoreCase("search")) {
forward=update(req, resp);
}

forward1(req,resp,forward);
}
private String update(HttpServletRequest req, HttpServletResponse resp) {
// TODO Auto-generated method stub
String forward=null;
try{
String Stritem=req.getParameter("item").trim();
String Strcontent=req.getParameter("content").trim();


Vector<sjInfo> list= new sjDaoImp().getOnesj(Stritem,Strcontent);
RequestDispatcher rd;
if( list==null||list.size()<1 ){

forward ="/user/login.jsp";
}else {
req.setAttribute("list",list);
forward="/user/search.jsp";

}
} catch (Exception es) {
es.printStackTrace();
forward = "/error.jsp";

}
return forward;
}
private void forward1(HttpServletRequest req,
HttpServletResponse resp, String url) throws ServletException,
IOException {
try {
req.getRequestDispatcher(url).forward(req, resp);
} catch (Exception e) {
e.printStackTrace();
}
}
}
bean代码:
public Vector<sjInfo> getOnesj(String item,String content){
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
sjInfo sjinfo1=null;
Vector<sjInfo> list = new Vector<sjInfo>();


try{
String Strsql = "select * from shangjia where "+item+"=?";
con = new connDB().getConnection();

pstmt = con.prepareStatement(Strsql);
pstmt.setString(1,content);
rs = pstmt.executeQuery();
while(rs.next()){
sjinfo1= new sjInfo();
sjinfo1.setSj_bh(rs.getString("sj_bh"));
sjinfo1.setSj_name(rs.getString("sj_name"));
sjinfo1.setSj_addr(rs.getString("sj_addr"));
sjinfo1.setSj_tel(rs.getString("sj_tel"));
sjinfo1.setSj_time(rs.getString("sj_time"));
sjinfo1.setSj_image(rs.getString("sj_image"));
sjinfo1.setSj_ms(rs.getString("sj_ms"));
list.add(sjinfo1);

}


}catch(Exception ex){
ex.printStackTrace();
}finally{
if(pstmt != null){
try {
pstmt.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
if(con != null){
try {
con.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
return list;
}
Search.jsp代码:<%@page contentType="text/html;charset=GB2312" %>
<%@page import="java.util.List"%>
<%@page import="java.util.Vector"%>
<%@page import="com.wjxl.Dao.sjInfo"%>
<%@page import="java.util.Iterator"%>
<jsp:useBean id="sjInfo" class="com.wjxl.Dao.sjInfo" scope="session"/>
<html>
<head>
<title>商家搜索</title>

</style>
</head>

<body>
<jsp:include page="ss.jsp"/>
<%
//new Venter ven=(Venter)list.get(i)
Vector<sjInfo> vv = (Vector<sjInfo>)request.getAttribute("list");
System.out.print(vv.size());
if(vv==null){
System.out.print("sadf");
}
else{
%>
<table width="80%" border=1 cellspacing="0" align="center">
<tr>
<td><font size="2" color="#0000FF">商家编号</font></td>
<td><font size="2" color="#0000FF">商家名称</font></td>
<td><font size="2" color="#0000FF">商家地址</font></td>
<td><font size="2" color="#0000FF">商家电话</font></td>
<td><font size="2" color="#0000FF">商家注册时间</font></td>
<td><font size="2" color="#0000FF">商家描述</font></td>
</tr>
<%

for(int i=0;i<vv.size();i++)
{
%>
<tr>
<td><font size="2"><%=(sjInfo)vv.get(i)+""%></font></td>

</tr>
<%}}
%>
</table>

</font></p>
</form>
</body>
</html>
<script type="text/javascript">
function check()
{
if (form1.content.value=="")
{
alert("请输入查询内容!");
form1.content.focus();
return false;
}
}
</script>

...全文
36 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧