新手提问,关于struts和jdon

06-05-17 csnowfox
刚接触jdon,发现在struts里面那一层非常不透明,

貌似jdonframework给封装了好多东西,

网上的文档都没太涉及到里面的整个程序跳转流程.

比如我的struts-config.xml里面

// 在此输入java代码
<action path="/serviceAction" type="com.jdon.strutsutil.ModelViewAction"
     name="userActionForm" scope="request"  validate="false">
<forward name="xxxxx" path="/result.jsp"/>
</action>
<p>

之后就迷惑了,ModelViewActon怎么找到我自己写的那个

services呢?

跟着之后跳转呢?从哪里有findmappin之类的?XXXXX

难道是通过formbean来jdonframework.xml找

// 在此输入java代码
<model key="userId" class ="com.c2.model.CUser">
      <actionForm name="userActionForm"/>
      <handler>
        <service ref="CUserService"> 
          <getMethod name="getUser" />
        </service>
      </handler>
</model>
<p>

里面的model的?

请高手指教.

banq
2006-05-17 15:53
是的,是通过formbean来jdonframework.xml找映射的。

formbean --- model --> service

banq
2006-05-17 16:24
一个FormBean对应struts-config.xml中的一个action配置;同时对应jdonframework.xml中的一个model CRUD流程配置,这里的桥梁FormBean是指FormBean名称,而不是FormBean类,同一个FormBean可以配置多个FormBean名称,这是在struts-config.xml的FormBeans中配置的。

csnowfox
2006-05-17 17:47
还有一个问题,我为了了解整个框架的运行.我先去调了dao的部分,在service那层就不通过数据库,直接返回一个对象.所以我没配置数据源啊之类(为了简化).

但是我在仿照例子建立一系列代码之后,发现代码运行得很不正常,一点不像文档中描述的.

下面是我的代码

struts-config.xml

// 在此输入java代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
  <data-sources />
  <form-beans>
    <form-bean name="userActionForm" type="com.c2.model.CUserActionForm" />
  </form-beans>
  <global-exceptions />
  <global-forwards />
  <action-mappings>
  	 <action path="/serviceAction" type="com.jdon.strutsutil.ModelViewAction"
     name="userActionForm" scope="request"  validate="false">
     <forward name="xxxxx" path="/result.jsp"/>
    </action>
  </action-mappings>
  <message-resources parameter="com.c2.struts.ApplicationResources" />
  <plug-in className="com.jdon.strutsutil.InitPlugIn">
    <set-property property="modelmapping-config" value="com.c2.struts.jdonframework.xml" />
  </plug-in>
</struts-config>
<p>

//我发现,在tomcat启动的时候,根本没出现plug-in加载的相关信息

jdonframework.xml

在包com.c2.struts下

// 在此输入java代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE app PUBLIC "-//JDON//DTD Framework 2005 1.0 //EN"	"http://127.0.0.1:8081/jdon/jdonframework.dtd">
<app>
  <models>
   <model key="userId" class ="com.c2.model.CUser">
      <actionForm name="userActionForm"/>
      <handler>
        <service ref="CUserService"> 
          <getMethod name="getUser" />
        </service>
      </handler>
    </model>
  </models>
  <services>
  	<pojoService name="CUserService" class="com.c2.server.CUserServerImp"/>
  </services>
</app>

<p>

//我已经按照例子文档写了CUser和CUserActionForm,CUserServerImp和CUserServer

在CUserServerImp里面只简单返回对象

// 在此输入java代码
package com.c2.server;

import com.c2.model.CUser;

public class CUserServerImp implements CUserServer{

	public CUser getUser(String userId) {
		return new CUser(new Long(1),"jingle");
	}

}
<p>

之后就报错了,还不在tomcat里面报错,只在页面jsp页面显示了错误信息,头痛,再看了两次开放指南都没发现问题.

请高手指教.

banq
2006-05-18 09:35
看了你的配置,你是想实现查询操作。

URL调用应该是:

http://localhost:8080/myweb/serviceAction.do?action=edit&userId=1

另外,建议在初次实验时,将主键类型都统一成字符串。

具体出错需要将主要出错信息显示出来看一下。

csnowfox
2006-05-18 15:14
我再次运行了该程序在jsp页面上报了如下的错误。

在我自己写的代码中,好像没有用到org/apache/struts/util/ModuleUtils

这个类啊。

// 在此输入java代码
type Exception report

message 

description The server encountered an internal error () that prevented it from fulfilling this request.

exception 

javax.servlet.ServletException: Servlet execution threw an exception


root cause 

java.lang.NoClassDefFoundError: org/apache/struts/util/ModuleUtils
	com.jdon.strutsutil.ModelViewAction.<init>(ModelViewAction.java:65)
	sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
	sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
	java.lang.reflect.Constructor.newInstance(Constructor.java:494)
	java.lang.Class.newInstance0(Class.java:350)
	java.lang.Class.newInstance(Class.java:303)
	org.apache.struts.util.RequestUtils.applicationInstance(RequestUtils.java:231)
	org.apache.struts.action.RequestProcessor.processActionCreate(RequestProcessor.java:326)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:268)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
	org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:507)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:689)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


<p>

banq
2006-05-21 12:59
你是struts 1.1,升级到struts 1.2吧

csnowfox
2006-05-21 16:44
怎么看出是struts版本的问题?

csnowfox
2006-05-21 17:28
谢谢板桥老师,实验成功.

csnowfox
2006-05-22 23:41
板桥老师,我继续对jdon框架学习,又碰到问题了

对于各个函数的接口我有很大的疑惑,我觉得你的文档里面

对接口的说明少了点,虽然跟着做或许能成功,但里面的机

制啊,接口参数啊,都不太了解.

我对上面的代码进行了如下扩展:

// 在此输入java代码
package com.c2.server;

import com.c2.model.CUser;
import com.jdon.controller.cache.CacheManager;
import com.jdon.controller.events.EventModel;

public class CUserServerImp implements CUserServer{
	
	public CUser getUser(String userId) {
		System.out.println("hello jdon" + userId);
		return new CUser(new Long(1),"jingle");
	}

	public void createUser(EventModel em) {
		CUser user = (CUser) em.getModel();
		System.out.println(user.getName());
	}

}
<p>

之后就报错了.

// 在此输入java代码
exception 

javax.servlet.ServletException: System error! please call system Admin.java.lang.Exception:  serviceAction Error:java.lang.Exception: execute service error: java.lang.Exception: java.lang.NullPointerException
	org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:523)
	org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:421)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
	org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause 

java.lang.Exception: System error! please call system Admin.java.lang.Exception:  serviceAction Error:java.lang.Exception: execute service error: java.lang.Exception: java.lang.NullPointerException
	com.jdon.strutsutil.ModelSaveAction.execute(ModelSaveAction.java:94)
	org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:419)
	org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:224)
	org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
	org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

<p>

对这个级别的错误,我还不懂得看.

我的理解:是不是若要调用createUser的方法必需要给CUserServerImp写一个构造函数?但是我又疑惑了,构造函数需要什么作为参数呢?在jdonframework.xml里面又需要怎么配置呢?

csnowfox
2006-05-22 23:43
还是把其他代码也贴出来吧

// 在此输入java代码
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE app PUBLIC "-//JDON//DTD Framework 2005 1.0 //EN"	"http://127.0.0.1:8081/jdonframe/jdonframework.dtd">
<app>
  <models>
   <model key="userId" class ="com.c2.model.CUser">
      <actionForm name="userActionForm"/>
      <handler>
        <service ref="CUserService"> 
          <getMethod name="getUser" />
          <createMethod name="createUser"/>
        </service>
      </handler>
    </model>
  </models>
  <services>
  	<pojoService name="CUserService" class="com.c2.server.CUserServerImp"/>
  </services>
</app>

<?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="userActionForm" type="com.c2.model.CUserActionForm" />
  </form-beans>
  <global-exceptions />
  <global-forwards />
  <action-mappings>
  	 <action path="/serviceAction" type="com.jdon.strutsutil.ModelViewAction"
     name="userActionForm" scope="request"  validate="false">
     <forward name="edit" path="/MyJsp.jsp"/>
    </action>
    <action path="/saveAction" type="com.jdon.strutsutil.ModelSaveAction"
     name="userActionForm" scope="request"  validate="false">
      <forward name="success" path="/result.jsp" />
      <forward name="failure" path="/result.jsp" />
    </action>
  </action-mappings>
  <message-resources parameter="com.c2.struts.ApplicationResources" />
  <plug-in className="com.jdon.strutsutil.InitPlugIn">
    <set-property property="modelmapping-config" value="com.c2.struts.jdonframework.xml" />
  </plug-in>
</struts-config>



<p>

猜你喜欢