页面可以这样改:
jsp文件
<%@ page contentType="text/html;charset=GBK" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/tld/bcinfo.tld" prefix="bcinfo" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>客户信息查询编辑</title>
</head>
<body>
<html:form action="/searchkehuxinxi.do?method=dokehuxinxisearch" method="post">
<table width="770" border="0">
<tr>
<td align="center" height="29"><strong>微机代码: </strong></td> <td height="29"> <html:text property="WEIJIBIANMA" size="20"/> </td>
<td align="center" width="79" height="29"> <input type="submit" name="search" value="查询" /> </td>
<td width="72" height="29"> </td>
<td width="117" height="29"> </td>
<td width="74" height="29"> </td>
<td width="85"> </td>
</tr>
<tr>
<td align="center" width="145" height="32"><strong>微机代码</strong></td>
<td align="center" width="168"><strong>纳税人代码</strong></td>
<td colspan="2" align="center"><strong>纳税人简称</strong></td>
<td align="center"><strong>地址</strong></td>
<td align="center"><strong>编辑</strong></td>
<td align="center"><strong>删除</strong></td>
</tr>
<logic:notEmpty name="users">
<logic:iterate id="user" name="users" type="com.wwtest.form.display_kehuxinxi">
<tr>
<td align="center" height="27"><strong><bean:write name="user" property="WEIJIBIANMA" /></strong></td>
<td align="center"><strong><bean:write name="user" property="NASHUIRENDAIMA" /></strong></td>
<td align="center" colspan="2"><strong><bean:write name="user" property="NASHUIRENJC" /></strong></td>
<td align="center" ><strong><bean:write name="user" property="DIZHI" /></strong></td>
<td align="center" > <input type="submit" name="Submit1" value="提交" /></td>
<td align="center"> <input type="button" name="Submit2" value="删除" onclick="delete('<bean:write name="user" property="WEIJIBIANMA"/>')" /></td>
</tr>
</logic:iterate>
</logic:notEmpty><script language="JavaScript">
<!--
function submit(){
document.loginForm3.submit();
} //删除记录
function delete(wjbm){
document.loginForm3.onsubmit="true";
document.loginForm3.action="/kehuxinxi_search.do?action=delete&wjbm="+wjbm;
document.loginForm3.submit();
}
//-->
</script>
</html:form>
</body>
</html>
jsp文件
<%@ page contentType="text/html;charset=GBK" language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tld/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/tld/bcinfo.tld" prefix="bcinfo" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>客户信息查询编辑</title>
</head>
<body>
<html:form action="/searchkehuxinxi.do?method=dokehuxinxisearch" method="post">
<table width="770" border="0">
<tr>
<td align="center" height="29"><strong>微机代码: </strong></td> <td height="29"> <html:text property="WEIJIBIANMA" size="20"/> </td>
<td align="center" width="79" height="29"> <input type="submit" name="search" value="查询" /> </td>
<td width="72" height="29"> </td>
<td width="117" height="29"> </td>
<td width="74" height="29"> </td>
<td width="85"> </td>
</tr>
<tr>
<td align="center" width="145" height="32"><strong>微机代码</strong></td>
<td align="center" width="168"><strong>纳税人代码</strong></td>
<td colspan="2" align="center"><strong>纳税人简称</strong></td>
<td align="center"><strong>地址</strong></td>
<td align="center"><strong>编辑</strong></td>
<td align="center"><strong>删除</strong></td>
</tr>
<logic:notEmpty name="users">
<logic:iterate id="user" name="users" type="com.wwtest.form.display_kehuxinxi">
<tr>
<td align="center" height="27"><strong><bean:write name="user" property="WEIJIBIANMA" /></strong></td>
<td align="center"><strong><bean:write name="user" property="NASHUIRENDAIMA" /></strong></td>
<td align="center" colspan="2"><strong><bean:write name="user" property="NASHUIRENJC" /></strong></td>
<td align="center" ><strong><bean:write name="user" property="DIZHI" /></strong></td>
<td align="center" > <input type="submit" name="Submit1" value="提交" /></td>
<td align="center"> <input type="button" name="Submit2" value="删除" onclick="delete('<bean:write name="user" property="WEIJIBIANMA"/>')" /></td>
</tr>
</logic:iterate>
</logic:notEmpty><script language="JavaScript">
<!--
function submit(){
document.loginForm3.submit();
} //删除记录
function delete(wjbm){
document.loginForm3.onsubmit="true";
document.loginForm3.action="/kehuxinxi_search.do?action=delete&wjbm="+wjbm;
document.loginForm3.submit();
}
//-->
</script>
</html:form>
</body>
</html>
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionForm;import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;
import java.util.ArrayList;import com.wwtest.dao.TestDao;
import com.wwtest.form.display_kehuxinxi;
import com.wwtest.util.DBUtil;/**
* Created by IntelliJ IDEA.
* User: administrator
* Date: 2007-5-11
* Time: 16:13:40
* To change this template use File | Settings | File Templates.
*/
public class kehuxinxi_search extends DispatchAction {
public ActionForward dokehuxinxisearch(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException {
TestDao td = new TestDao();
List users=new ArrayList();
display_kehuxinxi mform2 = (display_kehuxinxi) form;
String weijibianma = mform2.getWEIJIBIANMA(); System.out.println(weijibianma);
ActionForward forward = null; String action=request.getParameter("action");
if("delete".equals(action)){
String wjbm=request.getParameter("wjbm");
//下面就可以调用删除记录方法
...
}
if (weijibianma == null || weijibianma.trim().length() <= 0) {
request.setAttribute("errMessage", "微机代码不能为空");
return mapping.findForward("insertsb");
} /* String name = request.getParameter("textfield"); System.out.println("#######"+name);*/ try{ users=td.displayalkehukinxin(weijibianma); request.setAttribute("users",users); // DBUtil.commit();
return mapping.findForward("insert_cg");
} catch(Exception e){
try {
DBUtil.rollback();
DBUtil.closeConnection();
} catch (Exception e1) {
e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
e.printStackTrace(); }
return forward;
}}
<action path="/deletekehuxinxi" type="com.wwtest.action.kehuxinxi_delete"
name="loginForm3" parameter="method" scope="request">
<forward name="delete_sb" path="/delete_sb.jsp" />
<forward name="delete_cg" path="/delete_cg.jsp" />
</action>的deletekehuxinxi
错误提示:
type Status reportmessage /deletekehuxinxi.dodescription The requested resource (/deletekehuxinxi.do) is not available.IE框内空为:http://localhost:8080/deletekehuxinxi.do?%20action=delete&wjbm=88888888
中的/去掉试试
还有问号后边不能有空格
type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception javax.servlet.ServletException: Request[/deletekehuxinxi] does not contain handler parameter named 'method'. This may be caused by whitespace in the label text.
org.apache.struts.actions.DispatchAction.unspecified(DispatchAction.java:222)
org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:256)
org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:194)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
public class kehuxinxi_delete extends DispatchAction {
public ActionForward dodeletet(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException {
TestDao td = new TestDao(); ActionForward forward = null; String action=request.getParameter("action");
System.out.println("action: "+action);
if("delete".equals(action)){
String wjbm=request.getParameter("wjbm");
System.out.println("wjbm: "+wjbm); if (wjbm == null || wjbm.trim().length() <= 0) {
request.setAttribute("errMessage", "用户名不能为空");
return mapping.findForward("delete_sb");
} try{
td.delete_kehuxinxi(wjbm);
DBUtil.commit();
return mapping.findForward("delete_cg");
} catch(Exception e){
try {
DBUtil.rollback();
DBUtil.closeConnection();
} catch (Exception e1) {
e1.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
e.printStackTrace(); } }
return forward;
}}事务处理是:public boolean delete_kehuxinxi(String weijibianma)
throws Exception {
String strsql;
String aaa = null;
PreparedStatement ps = null;
strsql="delete from kehuxinxi1 where WEIJIBIANMA ='" +weijibianma+ "'"; try {
Connection conn = DBUtil.getCurrentConnection();
ps = conn.prepareStatement(strsql);
ps.execute();
return true;
} catch (Exception ex) {
ex.printStackTrace();
} finally {
DBUtil.freeStatement(ps);
try {
DBUtil.closeConnection();
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
在struts中一般都是继承Action类重写execute()方法
我自己解决了