zoukankan      html  css  js  c++  java
  • The import test cannot be resolved

     最近使用Myeclipse开发EJB程序实例遇到的问题。

    EJB Project 名:EJBHello(Stateless)

    EJBHello.java代码:

    package test;
    
    import javax.ejb.Stateless;
    import javax.ejb.Remote;
    import test.EJBHelloRemote;
    @Stateless
    @Remote(EJBHelloRemote.class) 
    public class EJBHello implements EJBHelloRemote {
    	public String sayTime(){
    		return "这是第一个EJB测试程序,现在时间为:"+new java.util.Date();
    	}
    }
    

    EJBHelloRemote.java代码:

    package test;
    
    import javax.ejb.Remote;
    
    @Remote
    public interface EJBHelloRemote {
    	public String sayTime();
    }
    

    EJB程序客户端的Web项目:EJBHelloClient

    EJBHello.jsp代码:

    <%@page import="test.*,javax.naming.*"%>                          //ERROR:The import test cannot be resolved
    <%@ page language="java" 
        pageEncoding="ISO-8859-1"%>
    <%
        try {
            InitialContext ctx = new InitialContext();
            EJBHelloRemote hello = (EJBHelloRemote) ctx       //ERROR:EJBHelloRemote cannot be resolved to a type
                    .lookup("EJBHello/remote");
            out.print(hello.sayTime());
        } catch (NamingException e) {
            out.print(e.getMessage());
        }
    %>

    部署到JBoss EAP6.2后,打开网页,结果如下:  


    JBWEB000065: HTTP Status 500 - JBWEB004062: Unable to compile class for JSP:

    JBWEB000309: type JBWEB000066: Exception report

    JBWEB000068: message JBWEB004062: Unable to compile class for JSP:

    JBWEB000069: description JBWEB000145: The server encountered an internal error that prevented it from fulfilling this request.

    JBWEB000070: exception

    org.apache.jasper.JasperException: JBWEB004062: Unable to compile class for JSP:

    JBWEB004060: An error occurred at line: 7 in the jsp file: /EJBHello.jsp
    EJBHelloRemote cannot be resolved to a type
    4: <%
    5: try {
    6: InitialContext ctx = new InitialContext();
    7: EJBHelloRemote hello = (EJBHelloRemote) ctx
    8: .lookup("EJBHello/remote");
    9: out.print(hello.sayTime());
    10: } catch (NamingException e) {


    JBWEB004060: An error occurred at line: 7 in the jsp file: /EJBHello.jsp
    EJBHelloRemote cannot be resolved to a type
    4: <%
    5: try {
    6: InitialContext ctx = new InitialContext();
    7: EJBHelloRemote hello = (EJBHelloRemote) ctx
    8: .lookup("EJBHello/remote");
    9: out.print(hello.sayTime());
    10: } catch (NamingException e) {


    JBWEB004211: Stacktrace:
    org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:85)
    org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:69)
    org.apache.jasper.compiler.JDTCompiler.generateClass(JDTCompiler.java:447)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:361)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:339)
    org.apache.jasper.compiler.Compiler.compile(Compiler.java:326)
    org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:606)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:308)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:309)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:242)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    JBWEB000072: note JBWEB000073: The full stack trace of the root cause is available in the JBoss Web/7.2.2.Final-redhat-1 logs.

    JBoss Web/7.2.2.Final-redhat-1


      原因应该是JSP不能import EJBHello项目中的test包。So, 应该怎样导入呢?

    相信自己!!

     

  • 相关阅读:
    电子书下载:Beginning ASP.NET 2.0 AJAX
    电子书下载:C# 4.0 How To
    电子书下载:Pragmatic Unit Testing in C# with NUnit
    7 个最好的.Net开源CMS系统
    电子书下载:Professional ASP.NET 2.0 Server Control and Component Development
    电子书下载:Beginning ASP.NET 2.0 Databases From Novice to Professional
    电子书下载:Professional .NET 2.0 Generics
    蛙蛙推荐:[算法练习]最长不完全匹配子串频率计算
    蛙蛙推荐:F#实现并行排序算法
    蛙蛙推荐:蛙蛙教你发明一种新语言之二代码生成
  • 原文地址:https://www.cnblogs.com/drl937676516/p/3588147.html
Copyright © 2011-2022 走看看