这几天做的是一个客户信息管理,到今天为止实现了主界面、客户信息的新增、查询、修改功能。




struts.xml和applicationContext.xml是很关键的存在,以及一系列的action,使得前端和后台的操作顺利的连接在一起。
这两个文件与各个action要相对应。如struts的class要与applicationContext的bean id相对应,而applicationContext的class要对应action的路径,jsp中的action又对应了struts的action name。
在applicationContext.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<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.0.xsd">
<!--数据库-配置数据连接池 -->
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName"
value="com.mysql.jdbc.Driver">
</property>
<property name="url"
value="jdbc:mysql://localhost:3306/dbssh">
</property>
<property name="username" value="root"></property>
<property name="password" value="123456"></property>
<property name="maxActive" value="100"></property>
<property name="maxWait" value="500"></property>
<property name="defaultAutoCommit" value="true"></property>
</bean>
<!--sessionFactory配置与管理 -->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="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>com/crm/bean/Cust.hbm.xml</value>
</list>
</property>
</bean>
<!--配置DAO-->
<bean id="custDao" class="com.crm.impl.CustDaoImpl">
<property name="sessionFactory">
<ref bean="sessionFactory"/>
</property>
</bean>
<!--配置service -->
<bean id="custService" class="com.crm.service.impl.CustServiceImpl">
<property name="custDao" ref="custDao"></property>
</bean>
<!--配置-新增保存saveAction -->
<bean id="custSaveAction" class="com.crm.action.CustSaveAction">
<property name="service">
<ref bean="custService"/>
</property>
</bean>
<!--配置-查询listAction -->
<bean id="listCustAction" class="com.crm.action.ListCustAction">
<property name="service" ref="custService"></property>
</bean>
<!--配置-删除deleteAction -->
<bean id="removeCustAction" class="com.crm.action.RemoveCustAction">
<property name="service" ref="custService"></property>
</bean>
<!--配置-typeAction -->
<bean id="typeAction" class="com.crm.action.TypeAction">
</bean>
<!--配置-条件查询findCdtAction -->
<bean id="findCdtAction" class="com.crm.action.FindCustByCdtAction">
<property name="findCdtService" ref="custService"></property>
</bean>
</beans>
在struts.xml中:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="customer" extends="struts-default">
<!-- 保存 -->
<action name="saveCust" class="custSaveAction">
<result name="success" type="redirect">/jsp/custInfo.jsp</result>
<result name="input">/custSave.jsp</result>
</action>
<!-- 查询 -->
<action name="listCust" class="listCustAction">
<result>/jsp/custInfo.jsp</result>
</action>
<!-- 删除 -->
<action name="delectCust" class="removeCustAction">
<result>/jsp/custInfo.jsp</result>
</action>
<!-- typeAcion下拉列表 -->
<action name="typeAction" class="typeAction">
<result></result>
</action>
<!-- 条件查询 -->
<action name="findCdtCustList" class="findCdtAction">
<result>/jsp/custInfo.jsp</result>
</action>
</package>
</struts>
设计了一个基础的数据库


这几天也遇到了一些问题:
1.出现了以下错误

解决方法:检查struts.xml、数据库连接池是否出错、架包是否冲突等,但都没有错误,最后在老师的帮助下,发现是没有连上网络,至于为什么一定要连网,老师也不得而知。
2.在实现新增功能的时候,设计了一个windonws函数,能够弹出一个新的窗口,但是操作的时候,程序没有报错,按的时候却没有反应。
解决方法:更换了个浏览器就可以执行了。
3.在点击新增窗口的时候,有时候可以成功,有时候却不可以。

对代码没有任何的修改,在操作时有时候会出现以下界面。

解决方法:目前这个问题还没有得到解决。
4.在进行保存时候,有时候会成功,有时候会出现以下错误

解决方法:原因是输入的字符类型或是字符长度与数据库设计的时候不符合。比如custno设计的时候是一个int类型,当你输入一个字符串的时候就不行了,性别设计的是一位,你输入的是两位也不行。
原文:http://www.cnblogs.com/ao2chen/p/7103688.html