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

问题描述

学习用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);

}

解决方案

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

解决方案二:

this.Tips=this.getB_OfficeDAO().findById(1).getOfficename().toString();中的B_officeDao是不是没有在你的action里面注入,也木有申明;要不你干脆new 一个B_officeDao在试试,要不你再你的Application.xml配置文件中加上一条

时间: 2024-10-31 21:15:38

ssh-学习用MyEclipse 2013开发SSH项目遇到java.lang.NullPointerException问题,请帮助!的相关文章

不知道为什么,每次在WTK自带的KToolbar新建J2ME项目时,总是弹出“不能产生项目XX,java.lang.NullPointerException&amp;amp;quot;

问题描述 不知道为什么,每次在WTK自带的KToolbar新建J2ME项目时,总是弹出"不能产生项目XX,java.lang.NullPointerException"那位达人知道怎么回事啊?小弟在线等!被这个问题弄了n久了...(apps里其他项目可以正常运行) 解决方案 解决方案二:KToolbar解决方案三:空指针异常,是程序写的不对,怪不得别人解决方案四:什么程序,请详细一点解决方案五:哦,是我没看清,这个情况我没遇到过,我用的是eclipse,帮顶

第三章 通过MyEclipse来开发Hibernate项目

        使用MyEclipse来开发Hibernate项目,这里是使用先写数据表用工具生成映射和实体类(第二章2.2)的方式,数据库使用的是mysql5. 3.1 通过MyEclipse中的Database Explorer来连接和管理数据库          展开MyEclipse的内置工具,选择MyEclipse Database Explorer         右击DB Browser中的空白区域,创建一个数据库连接项         选择Driver template,由于我们

没有方法异常-做ssh项目报java.lang.NoSuchMethodException

问题描述 做ssh项目报java.lang.NoSuchMethodException type Exception report message com.action.LoginAction.Login() description The server encountered an internal error that prevented it from fulfilling this request. exception java.lang.NoSuchMethodException: c

java web-Java web项目java.lang.NullPointerException

问题描述 Java web项目java.lang.NullPointerException java.io.IOException: Cannot run program "jad" (in directory "C:UsersAdministrator.net.sf.jadclipse1456277127516"): CreateProcess error=2, 系统找不到指定的文件. 解决方案 文件不存在,你看看路径对不对 解决方案二: 估计是路径的问题吧,,

visual studio 2013开发web项目打开网页时出错

问题描述 可以在任务栏看到IISexpress图标,我用的是win7,iisexpress8.0上网查原因,于是他们说要打开控制面板中打开和关闭windows功能中的iis服务打开控制面板,然后发现打开和关闭windows功能一片空白用了注册表的方法等都没用我的windows系统却无法更新也无法安装windowsupdate独立安装包好像什么都不行我真的不知道怎么办了,反正现在我无法开发任asp.net程序了 解决方案 解决方案二:你的系统是属于"阉割版"的,还是安装一个靠谱的&quo

android开发-java.lang.NullPointerException 在学习armenu时候遇到这问题的

问题描述 java.lang.NullPointerException 在学习armenu时候遇到这问题的 java.lang.NullPointerException at com.administrator_example.icm_arcmenu.view.ArcMenu.layoutButton(ArcMenu.java:137) 这句:mCButton.setOnClickListener(this); at com.administrator_example.icm_arcmenu.v

web 环境项目(intellj部署的tomcat) 重启时报 Exception in thread &quot;HouseKeeper&quot; java.lang.NullPointerException (转)

Exception in thread "HouseKeeper" java.lang.NullPointerException at org.logicalcobwebs.proxool.HouseKeeperController.getHouseKeeperToRun(HouseKeeperController.java:52) at org.logicalcobwebs.proxool.HouseKeeperThread.run(HouseKeeperThread.java:33

最近运行别人项目的时候,java.lang.NullPointerException 但是看了半天也不知道那个地方空指针了

问题描述 Struts Problem ReportStruts has detected an unhandled exception:Messages: File: com/lingx/system/security/SecurityContextFactory.javaLine number: 28Stacktracesjava.lang.NullPointerException com.lingx.system.security.SecurityContextFactory.getUse

【MyEcplise】导入项目报错:Errors running builder &amp;#39;JavaScript Validator&amp;#39; on project &amp;#39;项目名&amp;#39;. java.lang.ClassCastException

导入项目报错:Errors running builder 'JavaScript Validator' on project '项目名'. java.lang.ClassCastException   解决方法: project -->Properties  Builbers -->JavaScript Validator勾选去掉   解决问题!