NutzCN Logo
问答 NUTZ如何调用其他页面中的方法?
发布于 1723天前 作者 wx_chrohf6r75suj7q2r8fh 1522 次浏览 复制 上一个帖子 下一个帖子
标签:

有两个页面,一个后台为WorkerAction,一个后台为sendmessage,都需用到Dao使用FETCH或QUERY,login中某个方法需调用sendmessage.send的方法,我用new sendsessage().send,调用后报DAO为空,这个是啥子原因,单独在一个页面使用正常。

@IocBean
@At("/sendmessage")
@Ok("json")
@Fail("http:500")
public class sendmessage {
 @Inject
      protected Dao dao;

@At
@Ok("json")
 public String send(@Param("dn")String dn,@Param("smstext")String smstext) throws UnsupportedEncodingException
 {
     dn=URLDecoder.decode(dn,"UTF-8").trim().intern();
     smstext=URLDecoder.decode(smstext,"UTF-8").trim().intern();
     String sender="";

     String smstextid="",url="";
     smstext=smstext.trim();
     smsip Smsip=dao.fetch(smsip.class,Cnd.where("describer","=","ftth"));//在这里报dao为null
    if(Smsip==null)
       return "error:数据库中没有找到发送FTTH短信的账号";
    HttpSession session = null ;
    if(session.getAttribute("gh")!=null)
        sender=session.getAttribute("gh").toString();
    else
        sender="";
     if(dn.trim()=="")
         return "error:接收短信的号码为空";
     if(smstext.trim()=="")
         return "error:发送的短信内容为空";
     String [] dns=dn.trim().split(",");
     SimpleDateFormat df=new SimpleDateFormat("yyyyMMddHHmmssss");
     newsms Newsms=new newsms();
@IocBean
@At("/user")
@Ok("json")
@Fail("http:500")
public class WorkerAction {
 
	@Inject
	protected Dao dao;
     

@At
public String sendmessage(String dn,String smstext) throws UnsupportedEncodingException
{
//smsip Smsip=dao.fetch(smsip.class,Cnd.where("describer","=","ftth"));
dn=dn.trim();
return new sendmessage().send(dn,smstext);

}


``` 20-04-04 17:03:46.455 WARN [http-nio-8089-exec-302] Error@/user/dealyzm : java.lang.NullPointerException at main.sendmessage.send(sendmessage.java:53) at main.WorkerAction.sendmessage(WorkerAction.java:642) at main.WorkerAction.tjyzm(WorkerAction.java:620) at main.WorkerAction.dealyzmid(WorkerAction.java:564) at main.WorkerAction.dealyzm(WorkerAction.java:491) at main.WorkerAction$FM$dealyzm$ac29c7ca8e2c75d8c33ec0f0e357d1d1.invoke(WorkerAction.java) at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:31) at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44) at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:38) at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44) at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58) at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44) at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123) at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44) at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27) at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44) at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15) at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44) at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67) at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31) at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:202) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:543) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:688) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:609) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:818) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1623) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Thread.java:748)
5 回复

试了UI下直接把相关的参数固话,不用从数据库度,即不用DAO,一切正常,怎么初始化DAO?

不要调用"其他页面"的方法, 把可重用的逻辑放到Service类

new XXX()是不会有ioc注入的.

在这个里面?

public class MainSetup implements Setup {

        @Override
	public void init(NutConfig conf) {
		Ioc ioc = conf.getIoc();
                
		Dao dao = ioc.get(Dao.class);
                
                Daos.createTablesInPackage(dao, "sjk", false);
                
                //MyListener mylistener=ioc.get(MyListener.class);
                
                sendmessage Sendmessage=ioc.get(sendmessage.class);
                //tcpip Tcpip=ioc.get(tcpip.class);
                
          
	}
	
添加回复
请先登陆
回到顶部