小弟我刚学完SSH,做了一个留言管理程序,但出现了以下问题:1) 我用到了动态Form和验证框架,用来验证在添加时非空。但实际上无效
2) 方法和Action中的方法都正确,但是插不进去数据,也没报任何异常。(根本没执行Action中的方法)配置文件没错哪位大哥有空,帮我瞧瞧代码吧,看问题是出在哪?不能发附件,知道的QQ叫我吧516121830,不胜感激!
2) 方法和Action中的方法都正确,但是插不进去数据,也没报任何异常。(根本没执行Action中的方法)配置文件没错哪位大哥有空,帮我瞧瞧代码吧,看问题是出在哪?不能发附件,知道的QQ叫我吧516121830,不胜感激!
解决方案 »
- 怎么在jsp中播放 rmvb ,格式的视频。
- tomcat集群session复制问题,大牛们帮帮忙
- javamail邮件系统源代码下载(b/s)
- 关于ssh去实现细颗粒的功能权限
- struts+jdon+hibernate框架 现在应用的如何?企业用的广不?该不该深究?
- 幫幫忙!----------------------------------聽說標題要長才會多人看
- 从数据库里面取数据写入<html:select>
- art,birt还是ireport
- 哪里有讲解weblogic中配置ejb的详细文章??
- 请教,我该如何在weblogic 上 部署EJB ?
- 求一SH框架的BBS系统
- 进来看看这是什么技术实现的?是否有开源的
网上动态Form例子挺好使的
楼主照着做做
private NoteDAO notedao ;
public NoteDAO getNotedao() {
return notedao;
}
public void setNotedao(NoteDAO notedao) {
this.notedao = notedao;
}
/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward insert(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaValidatorForm noteForm = (DynaValidatorForm) form;
// TODO Auto-generated method stub
System.out.println("--------------------->");
Note note = new Note() ;
note.setTitle(noteForm.getString("title")) ;
note.setContent(noteForm.getString("content")) ;
note.setAuthor(noteForm.getString("author")) ;
try {
this.notedao.insert(note) ;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return mapping.findForward("insertdo");
}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 >
<form-bean name="noteForm" type="org.apache.struts.validator.DynaValidatorForm">
<form-property name="title" type="java.lang.String" />
<form-property name="content" type="java.lang.String" />
<form-property name="author" type="java.lang.String" />
</form-bean> </form-beans> <global-exceptions />
<global-forwards />
<action-mappings >
<action
attribute="noteForm"
input="/add_note.jsp"
name="noteForm"
parameter="status"
path="/note"
scope="request"
type="org.zgf.note.struts.action.NoteAction" validate="true">
<forward name="insertdo" path="/insert_do.jsp"></forward>
</action> </action-mappings>
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"></controller>
<message-resources parameter="org.zgf.note.struts.ApplicationResources" />
<plug-in className="org.apache.struts.validator.ValidatorPlugIn">
<set-property property="pathnames"
value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
</plug-in> <plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/classes/applicationContext.xml" />
</plug-in>
</struts-config>applicationContext.xml
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="org.gjt.mm.mysql.Driver">
</property>
<property name="url" value="jdbc:mysql://localhost:3306/mldn"></property>
<property name="username" value="root"></property>
<property name="password" value="zhugfily"></property>
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref bean="dataSource" />
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.MySQLDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
<property name="mappingResources">
<list>
<value>org/zgf/note/model/Note.hbm.xml</value></list>
</property></bean>
<bean id="hibernatetemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<bean id="notedao" class="org.zgf.note.dao.NoteDAO" abstract="true"></bean>
<bean id="notedaoimpl" class="org.zgf.note.impl.NoteDAOImpl" parent="notedao">
<property name="hibernateTemplate">
<ref bean="hibernatetemplate"/>
</property>
</bean>
<bean name="/note" class="org.zgf.note.struts.action.NoteAction">
<property name="notedao">
<ref bean="notedaoimpl"/>
</property>
</bean>
</beans>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/applicationContext.xml
</param-value>
</context-param>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>add_note.jsp
<%@ page language="java" pageEncoding="gbk"%><%@ 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" %><html:html lang="true">
<head>
<title>添加留言</title>
</head>
<body>
<center>
<h3>欢迎进入添加留言页面</h3><hr>
<html:form action="note.do" method="post" onsubmit="return validateNoteForm(this)">
标题:<html:text property="title"></html:text><br>
内容: <html:textarea property="content"></html:textarea><br>
作者: <html:text property="author"></html:text><br>
<input type="hidden" name="status" value="insert"/>
<html:submit value="提交"></html:submit><html:reset value="重置"></html:reset>
</html:form>
<html:javascript formName="noteForm"/>
</center>
</body>
</html:html>
<controller processorClass="org.springframework.web.struts.DelegatingRequestProcessor"></controller>这和你那的效果是一样的
改成type=org.springframework.web.struts.DelegatingActionProxy
试下
设置双断点 看看。
必须执行execute()方法。