站内搜索: 请输入搜索关键词

当前页面: 开发资料首页J2EE 专题(我的分快没了)大家帮忙看看吧,我捣鼓一天了,筋疲力尽!!!为什么这个Struts始终徘徊在表单验证这里,不再往下走了,似乎Action的exce

(我的分快没了)大家帮忙看看吧,我捣鼓一天了,筋疲力尽!!!为什么这个Struts始终徘徊在表单验证这里,不再往下走了,似乎Action的exce

摘要: (我的分快没了)大家帮忙看看吧,我捣鼓一天了,筋疲力尽!!!为什么这个Struts始终徘徊在表单验证这里,不再往下走了,似乎Action的exce


就是用户填写完姓名、密码、标题、内容后,点击提交按钮应该到达success这个页面,但是,我始终实现不了,始终徘徊在表单验证这里,不往下走了,似乎根本就没有调用Action的excecute()方法;
我到现在也没找到是哪里的错误,人多力量大,大家都帮忙看看是哪里的错误吧,我鼓捣一天了,筋疲力尽。。。。
我把代码贴上来:
send.jsp:


<%@ page language="java" import="java.sql.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" errorPage="" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>

HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%
response.setHeader("Cache-Control","no-store");
response.setHeader("Pragma","no-cache");
response.setDateHeader("Expires",0);
%>

<head>



</head>

<body>
留言板





<table width="200" border="0" align="center" cellspacing="0" >
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan=2></td>
<td colspan=2></td>
</tr>
<tr>
<td colspan=2></td>
<td colspan=2></td>
</tr>
<tr>
<td colspan="4" align="center" >

</td>
</tr>
</table>




</body>





SendForm.java:

package com.aa.struts.form;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
public final class SendForm extends ActionForm
{
private String name=null;
private String password=null;
private String title=null;
private String content=null;
Connection co=null;
Statement st=null;
ResultSet rs=null;
String DBDriver="odbc.jdbc.driver.OracleDriver";
String ConnStr="jdbc:oracle:thin:@localhost:1521:Grace";
public SendForm()
{

}
public String getName()
{
return (this.name);
}
public void setName(String name)
{
this.name=name;
}
public String getPassword()
{
return password;
}

public void setTitle(String title )
{
this.title=title;
}
public String getTitle()
{
return this.title;
}
public void setContent(String content)
{
this.content=content;
}
public String getContent()
{
return this.content;
}
public ResultSet chk_liuyan()
{
try
{
co=DriverManager.getConnection(ConnStr,"system","ffffff");
st=co.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
String sql="select name from guestbook where '"+name+"'=name ";
rs=st.executeQuery(sql);
}
catch(Exception e)
{
e.printStackTrace();
}
return rs;
}
public ActionErrors validate(ActionMapping mapping,HttpServletRequest request)
{
ActionErrors errors=new ActionErrors();
if((name==null)||(name.length()<1))
errors.add("name",new ActionError("error.name.required"));
if((password==null)||(password.length()<1))
errors.add("password",new ActionError("error.password.required"));
if((title==null)||(title.length()<1))
errors.add("title",new ActionError("errors.title.required"));
if((content==null)||(content.length()<1))
errors.add("content",new ActionError("errors.content.required"));
return errors;
}
}




SendAction.java:

package com.aa.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.aa.struts.data.Connect;
import com.aa.struts.form.SendForm;


public class SendAction extends Action {


public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)throws Exception
{
SendForm sendForm = (SendForm) form;

Connect con=new Connect();
ActionErrors errors=new ActionErrors();
String name=new String(sendForm.getName().getBytes("8859-1"));

String title=new String(sendForm.getTitle().getBytes("8859-1"));
String content=new String(sendForm.getContent().getBytes("8859-1"));
ResultSet rs1=sendForm.chk_liuyan();
String u_name=rs1.getString("name");
if(name.trim().equals(u_name))
{ errors.add("name",new ActionError("error.username.exist"));
saveErrors(request,errors);
return (mapping.findForward("failure"));
}
int flag=con.liuyan(title,content);

if(flag==1)
{
return (mapping.findForward("success"));
}
return (mapping.findForward("failure"));
}
}



Struts-config.xml:

<?xml version="1.0" encoding="UTF-8"?>
struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">



<form-beans >
<form-bean name="sendForm" type="com.aa.struts.form.SendForm" />

</form-beans>




attribute="sendForm"
input="/send.jsp"
name="sendForm"
path="/send"
type="com.aa.struts.action.SendAction">











public final class SendForm extends ActionForm

这个类里面不该有业务逻辑, 连接也不要放在这里, actionForm类只是收集jsp页面的数据的!

为什么没有执行你所执行的任务, 应该是你的配置有问题, 自己多调试一下吧


提交的时候有没有什么错误提示?


↑返回目录
前一篇: 无法连接到远程JBoss MQ服务器(linux),但连接localhost和其他windows工作站都可以
后一篇: Weblogic使用JDBC新手问题--JDBC driver is not on the CLASSPATH