sunrealonetwo 2013-05-11 10:14 采纳率: 0%
浏览 3540

学习用MyEclipse 2013开发SSH项目遇到java.lang.NullPointerException问题,请帮助!

SaveOfficeAction.java出错:java.lang.NullPointerException

package we.app.action;

import we.app.data.*;

import com.opensymphony.xwork2.ActionSupport;

public class SaveOfficeAction extends ActionSupport {
    private IOffice B_Office;
    private IOfficeDAO B_OfficeDAO;
    private String Tips;

    public IOffice getB_Office() {
        return B_Office;
    }

    public void setB_Office(IOffice b_Office) {
        B_Office = b_Office;
    }

    public IOfficeDAO getB_OfficeDAO() {
        return B_OfficeDAO;
    }

    public void setB_OfficeDAO(IOfficeDAO b_OfficeDAO) {
        B_OfficeDAO = b_OfficeDAO;
    }

    public String getTips() {
        return Tips;
    }

    public void setTips(String tips) {
        Tips = tips;
    }

    public String execute() throws Exception
    {
        this.Tips=this.getB_OfficeDAO().findById(1).getOfficename().toString();
        //this.Trans_OfficeDAO.save(this.B_Office);
        return SUCCESS;
    }


}

1、index.jsp:

   <%@taglib uri="/struts-tags" prefix="s"%><%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">

    <title>My JSP 'index.jsp' starting page</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
  </head>

  <body>
    <s:form action="SaveOffice">
        <s:textfield name="B_Office.officename" label="officename"></s:textfield>
        <s:submit></s:submit>
    </s:form>
    <br>
  </body>
</html>

2、hibernate.cfg.xml:

   <?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
          "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
          "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools.                   -->
<hibernate-configuration>

    <session-factory>
        <property name="dialect">org.hibernate.dialect.SQLServerDialect</property>
        <property name="connection.url">
            jdbc:jtds:sqlserver://192.168.0.100:4628/tnew
        </property>
        <property name="connection.username">sa</property>
        <property name="connection.password">111</property>
        <property name="connection.driver_class">
            net.sourceforge.jtds.jdbc.Driver
        </property>
        <property name="myeclipse.connection.profile">
            sqlserverjtds
        </property>
        <mapping resource="we/app/data/Peop.hbm.xml" />
        <mapping resource="we/app/data/Office.hbm.xml" />

    </session-factory>

</hibernate-configuration>

3、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"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xmlns:aop="http://www.springframework.org/schema/aop" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
           http://www.springframework.org/schema/tx 
           http://www.springframework.org/schema/tx/spring-tx-3.1.xsd 
           http://www.springframework.org/schema/aop 
           http://www.springframework.org/schema/aop/spring-aop-3.1.xsd"
    >


    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="configLocation"
            value="classpath:hibernate.cfg.xml">
        </property>
    </bean>

    <bean id="PeopDAO" class="we.app.data.PeopDAO">
            <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>
    <bean id="B_OfficeDAO" class="we.app.data.OfficeDAO">
    <property name="sessionFactory" ref="sessionFactory"></property>
    </bean>

    <bean id="B_Office" class="we.app.data.Office"></bean>
    <bean id="B_Peop" class="we.app.data.Peop"></bean>


    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
       <property name="sessionFactory">
         <ref bean="sessionFactory"/>
       </property>
    </bean>

<bean id="Trans_OfficeDAO"
  class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
  <property name="transactionManager">
   <ref bean="transactionManager" />
  </property>
  <property name="target">
   <ref local="B_OfficeDAO" />
  </property>
  <property name="transactionAttributes">
   <props>
    <prop key="*">PROPAGATION_REQUIRED</prop>
   </props>
  </property>
 </bean>


</beans>

4、

package we.app.data;

import java.util.List;

public interface IOfficeDAO {

    // property constants
    public static final String OFFICENAME = "officename";

    public abstract void save(IOffice transientInstance);

    public abstract void delete(IOffice persistentInstance);

    public abstract IOffice findById(java.lang.Integer id);

    public abstract List findByExample(IOffice instance);

    public abstract List findByProperty(String propertyName, Object value);

    public abstract List findByOfficename(Object officename);

    public abstract List findAll();

    public abstract IOffice merge(Office detachedInstance);

    public abstract void attachDirty(IOffice instance);

    public abstract void attachClean(IOffice instance);

}
  • 写回答

2条回答 默认 最新

  • 秋水 2013-05-11 13:52
    关注

    你好歹把出错信息贴出来啊

    评论

报告相同问题?

悬赏问题

  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?