做了个分页显示 其中每行最后添加了一个删除操作 但是每次都是传一个空的参数是怎么回事?下面是代码 望各位大大帮忙解决一下~ 谢谢了Action:
OffDeleteAction.java
package org.zdgy.struts.action;import java.util.List;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.zdgy.struts.daoimpl.Offdaoimpl;
//import org.zdgy.struts.daoimpl.Offdeleteimpl;public class OffDeleteAction extends Action { private String personid;
private String s="SUCCESS";
private String input="INPUT"; public String getPersonid() {
return personid;
} public void setPersonid(String personid) {
this.personid = personid;
}

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
Offdaoimpl od = new Offdaoimpl();
int i = od.delete(personid);

ActionForward forward = new ActionForward("qingjiadelete.do?personid");
//ActionForward error = new ActionForward("error.do");

    forward.setRedirect(true);
     
if(i > 0){
return mapping.findForward("offdelete");
}else{
return mapping.findForward("offdelete");
}

}DAO:
Offdaoimpl.java
package org.zdgy.struts.daoimpl;import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;import org.zdgy.struts.dao.persondao;
import org.zdgy.struts.dbc.personConnection;
import org.zdgy.struts.po.offpo;public class Offdaoimpl implements persondao {
personConnection conn = new personConnection();
PreparedStatement pre = null;
ResultSet res = null;
List list = new ArrayList(); public List findall(String keyword) { // boolean flag = false;
if (keyword == null || "".equals(keyword)) { String sql = "select * from off"; 
try {
pre = conn.getconnection().prepareStatement(sql);
res = pre.executeQuery();
while (res.next()) {
offpo po = new offpo();
po.setId(res.getInt(1));
po.setName(res.getString(2));
po.setBegin(res.getString(3));
po.setTimelong(res.getString(4));
po.setReason(res.getString(5));
po.setAgree(res.getString(6));
po.setTime(res.getString(7));
po.setRe(res.getString(8));
list.add(po);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else {
String sql = "delect * from off where id=?"; try {
pre = conn.getconnection().prepareStatement(sql);
pre.setString(1, keyword);
res = pre.executeQuery();
while (res.next()) {
offpo po = new offpo();
po.setId(res.getInt(1));
po.setName(res.getString(2));
po.setBegin(res.getString(3));
po.setTimelong(res.getString(4));
po.setReason(res.getString(5));
po.setAgree(res.getString(6));
po.setTime(res.getString(7));
po.setRe(res.getString(8));
list.add(po);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return list;
}
/* public int findnum1(){ 
 List list = new ArrayList(); 
 list = findall(); 
 int num = list.size(); return num; }*/
 
public int findnum() {
String sql = "select count(*) from off";
int num = 0;
try {
pre = conn.getconnection().prepareStatement(sql);
res = pre.executeQuery();
while (res.next()) {
num = res.getInt(1);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
res.close();
pre.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
conn.closed(); }
return num;
}
public int delete (String personid) {
int i = 0 ;
String sql = "delect * from off where id=?";
try {
pre = conn.getconnection().prepareStatement(sql);
pre.setString(1, personid); 
i = pre.executeUpdate();
}catch(Exception e){
e.printStackTrace();
}
return i;
}}
struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
  <data-sources />
  <form-beans />
  <global-exceptions />
  <global-forwards />
  <action-mappings >
   <action path="/test" type="org.zdgy.struts.action.testAction">
   <forward name="div" path="/divpage.jsp"></forward>
   </action>
   <action path="/qingjia" type="org.zdgy.struts.action.OffAction">
   <forward name="off" path="/off.jsp"></forward>
   </action>
   <action path="/qingjiadelete" type="org.zdgy.struts.action.OffDeleteAction" scope="request">
       <forward name="offdelete" path="/qingjia.do" redirect="false"></forward>
   </action>
  </action-mappings>
  
  <message-resources parameter="org.zdgy.struts.ApplicationResources" />
</struts-config>最后是off.jsp
<%@ page language="java" pageEncoding="GB18030" import ="java.util.*,org.zdgy.struts.po.*"%>
<!--<a href="qingjiadelete.do?personid=" onclick="return del();">删除</a> -->
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%@ taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html:html lang="true">
  <head>
    <html:base />
    <title>请假信息</title>
  </head>
  
  <body>
   <%  
   int currentpage = 1;  
   int linesize = 5;  
   int allpage = Integer.parseInt(request.getAttribute("num").toString()); 
   int pagesize=(allpage+linesize-1)/linesize; 
   try{ 
   currentpage=Integer.parseInt(request.getParameter("cp")); 
   }catch(Exception e){} 
    String keyword = request.getParameter("inp");
    %>
    
    <script type="text/javascript">
     function openpage(curpage){
     document.spage.cp.value=curpage;
     document.spage.submit();
     }
     function selitem(){
     document.spage.cp.value=document.spage.sel.value;
     document.spage.submit();
     }
     function del(){
     var flag = false;
     if(confirm('您确定要删除么?')){
                 flag = true;
             }
             return flag;
     }
    </script>
<h2 align="center">财务工资管理系统</h2>
    <table border="1" align="center">
     <tr>
     <td align="center">
     员工编号
     </td>
     <td align="center">
     姓名
     </td>
     <td align="center">
     开始时间
     </td>
     <td align="center">
     天数
     </td>
     <td align="center">
     原因
     </td>
     <td align="center">
     批准人
     </td>
     <td align="center">
     编辑时间
     </td>
     <td align="center">
     备注
     </td>
     <td align="center">
     操作
     </td>
     </tr>
     <%
     List list = new ArrayList();
          list = (List)request.getAttribute("list");
          Iterator it = list.iterator();
          if(it.hasNext()){
          for(int x=0;x<(currentpage-1)*linesize;x++){
          it.next();
          }
          for(int i=0; i<linesize;i++){
          if(it.hasNext()){
          offpo  po = (offpo)it.next();
         
     %>
     <tr>
     <td align="center">
     <%=po.getId() %>
     </td>
     <td align="center">
     <%=po.getName() %>
     </td>
     <td align="center">
     <%=po.getBegin() %>
     </td>
     <td align="center">
     <%=po.getTimelong() %>
     </td>
     <td align="center">
     <%=po.getReason() %>
     </td>
     <td align="center">
     <%=po.getAgree() %>
     </td>
     <td align="center">
     <%=po.getTime() %>
     </td>
     <td align="center">
     <%=po.getRe() %>
     </td>
     <td align="center">
         <a href="qingjiadelete.do?personid=<%=po.getId()%>" onclick="del();">删除</a>
     </td>
     </tr>
     <%
      }
     }
     }
      %>
    </table>
 
    <center><form action="qingjia.do" name="spage">
     请输入需要查询的ID:<input name="inp" type = "text" 
     value="<%=keyword==null||"".equals(keyword)?"":keyword %>" size="5">
     <input type="submit" value="提交">
     <input type="submit" value="首页" onclick="openpage(1)"
     <%=currentpage == 1?"disabled":"" %>>
     <input type="submit" value="上一页" onclick="openpage(<%=currentpage-1 %>)"
     <%=currentpage == 1?"disabled":"" %>>
     <input type="submit" value="下一页" onclick="openpage(<%=currentpage+1 %>)"
     <%=currentpage == pagesize?"disabled":"" %>>
     <input type="submit" value="尾页" onclick="openpage(<%=pagesize %>)"
     <%=currentpage == pagesize?"disabled":"" %>>
     <input name="cp" value="" type="hidden">
     <select name="sel" onchange="selitem()">
     <%
     for(int x=1;x<=pagesize;x++){
      %>
     <option value="<%=x %>" <%=x==currentpage?"selected":"" %>><%=x %></option>
     <%
     }
      %>
     </select>
    </form>
    </center>
  </body>
</html:html>
最后是错误信息:
java.sql.SQLException: Syntax error or access violation,  message from server: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'delect * from off where id=null' at line 1"新手 分不多 谢谢大家~

解决方案 »

  1.   

    我也是初学jsp,不过看了一下,你在sql里头用的是select ×,这样在rs.set的时候,用1.2.3不知道可以吗?
    是不是可以把字段都选出来。比如这样
    select id, name......from table另外。你建立的connection好像都没有关。这样链接太多了,数据库会出问题的。
      

  2.   

    另外 throws Exception {
            Offdaoimpl od = new Offdaoimpl();
            int i = od.delete(personid);
            
            ActionForward forward = new ActionForward("qingjiadelete.do?personid");
            //ActionForward error = new ActionForward("error.do");
            
            forward.setRedirect(true);
             
            if(i > 0){
                return mapping.findForward("offdelete");
            }else{
                return mapping.findForward("offdelete");
            }
            
        }这个里头,这个personid是怎么传到Action里头的啊?好像没有用form得到personid。可以用System.out.println看看你的personid在每个步骤都是啥值
      

  3.   

    select * 返回一个结果集 然后再按需取数据我也用过<html:link>这个标签 也不行。。 不知道action和struts-config.xml具体应该怎么写。。
    链接都有关闭的啊
      

  4.   

    我是想在URL里传递这个personid 不知道在struts1里怎么实现 有的代码图省事了 呵呵
      

  5.   

    'delect * from off where id=null' 你的sql语句有问题嘛.!
    action中request.getParameter("id")看这两个名字是否一样. 如果这个名字跟界面上的名字不一样拿到就是null
      

  6.   

    谢谢大家了 终于搞成了还是6L的大大认真啊 谢谢~还有delete语句也写错了。。不认真了 呵呵