代码如下:<%--
Document : index
Created on : 2009-9-2, 14:40:05
Author : Administrator
--%><%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@page import="javax.naming.*,
java.util.Properties,
javax.rmi.PortableRemoteObject,
java.math.BigDecimal,
mypackage.*"%> <html>
<head>
<title>
pll
</title>
</head>
<body>
<h1>
JBuilder Generated JSP
</h1>
<%!
private Context getInitialContext() throws Exception {
String url = "t3://localhost:7001";
String user = null;
String password = null;
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
} return new InitialContext(properties);
}
catch(Exception e) { throw e;
}
}
%> <%! public HelloWorld create() { try {
HelloWorld = HelloWorldHome.create();
}
catch(Exception e) {
e.printStackTrace();
}
return HelloWorld;
}
%>
<% try {
Context ctx = getInitialContext();
Object ref = ctx.lookup("HelloWorld");
HelloWorldHome = (HelloWorldHome) PortableRemoteObject.narrow(ref, HelloWorldHome.class);
HelloWorld = create();
String allName=HelloWorld.hello("hello,this is a jsp!!!");
}
catch(Exception e) {
e.printStackTrace();
}
%> <% out.println("allName");%>
</body>
</html>
运行时提示如下:
Compilation of JSP File '/index2.jsp' failed:
--------------------------------------------------------------------------------
index2.jsp:55:15: 在此位置找不到任何具有此名称的变量或字段。
HelloWorld = HelloWorldHome.create(); ^--------^
index2.jsp:55:28: 无法从 static 上下文访问此方法。
HelloWorld = HelloWorldHome.create(); ^---------------------^
index2.jsp:60:20: 在此位置找不到任何具有此名称的变量或字段。
return HelloWorld; ^--------^
index2.jsp:68:24: 在此位置找不到任何具有此名称的变量或字段。
HelloWorldHome = (HelloWorldHome) PortableRemoteObject.narrow(ref, HelloWorldHome.class); ^------------^
index2.jsp:69:24: 在此位置找不到任何具有此名称的变量或字段。
HelloWorld = create(); ^--------^
index2.jsp:70:41: 无法从 static 上下文访问此方法。
String allName=HelloWorld.hello("hello,this is a jsp!!!"); ^----------------------------------------^但是,HelloWorld这个ejb已经发布成功了,用客户端程序调用都成功,为什么一用jsp就不行了呢?而且我已经把HelloWorld.jar加入classpath了,还是不行。
请高手指点。
Document : index
Created on : 2009-9-2, 14:40:05
Author : Administrator
--%><%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@page import="javax.naming.*,
java.util.Properties,
javax.rmi.PortableRemoteObject,
java.math.BigDecimal,
mypackage.*"%> <html>
<head>
<title>
pll
</title>
</head>
<body>
<h1>
JBuilder Generated JSP
</h1>
<%!
private Context getInitialContext() throws Exception {
String url = "t3://localhost:7001";
String user = null;
String password = null;
Properties properties = null;
try {
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if (user != null) {
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
} return new InitialContext(properties);
}
catch(Exception e) { throw e;
}
}
%> <%! public HelloWorld create() { try {
HelloWorld = HelloWorldHome.create();
}
catch(Exception e) {
e.printStackTrace();
}
return HelloWorld;
}
%>
<% try {
Context ctx = getInitialContext();
Object ref = ctx.lookup("HelloWorld");
HelloWorldHome = (HelloWorldHome) PortableRemoteObject.narrow(ref, HelloWorldHome.class);
HelloWorld = create();
String allName=HelloWorld.hello("hello,this is a jsp!!!");
}
catch(Exception e) {
e.printStackTrace();
}
%> <% out.println("allName");%>
</body>
</html>
运行时提示如下:
Compilation of JSP File '/index2.jsp' failed:
--------------------------------------------------------------------------------
index2.jsp:55:15: 在此位置找不到任何具有此名称的变量或字段。
HelloWorld = HelloWorldHome.create(); ^--------^
index2.jsp:55:28: 无法从 static 上下文访问此方法。
HelloWorld = HelloWorldHome.create(); ^---------------------^
index2.jsp:60:20: 在此位置找不到任何具有此名称的变量或字段。
return HelloWorld; ^--------^
index2.jsp:68:24: 在此位置找不到任何具有此名称的变量或字段。
HelloWorldHome = (HelloWorldHome) PortableRemoteObject.narrow(ref, HelloWorldHome.class); ^------------^
index2.jsp:69:24: 在此位置找不到任何具有此名称的变量或字段。
HelloWorld = create(); ^--------^
index2.jsp:70:41: 无法从 static 上下文访问此方法。
String allName=HelloWorld.hello("hello,this is a jsp!!!"); ^----------------------------------------^但是,HelloWorld这个ejb已经发布成功了,用客户端程序调用都成功,为什么一用jsp就不行了呢?而且我已经把HelloWorld.jar加入classpath了,还是不行。
请高手指点。
解决方案 »
- JAVA WEB入门 求怎么循序渐进开始学习
- js的删除表格操作问题
- jspsmartupload在myeclipse+tomcat中的配置
- ckfinder的core文件夹为空,然后上传文件的时候说找不到core的路径
- 请教textarea方面的问题,谢谢。。。
- 为什么刷新后客户端内存不断上升
- 一个关于数据库的问题.
- 过滤器问题请指点????????????//****************************//
- 谁能帮我看看这段程序问题出在哪里?在线等,立即送分!
- 大家说说,微软的jdbc是不是很烂,好多方法不支持
- tagsupport是否会做session清空的操作doEndTag()为什么时获取不session的内容
- 哪位仁兄知道长天科技(南京研发中心)的java笔试题啊? 在线等!!!
变量名和类名一样样的 不管对不对老兄都是太有才了HelloWorldHome 作为一个全局变量 你的定义哪去了?