当前位置: 技术问答>java相关
javabean的问题
来源: 互联网 发布时间:2017-03-11
本文导语: 各位大侠 帮个忙 cc.jsp: Untitled this is test2.jsp: UerEnv.java: package test; public class UserEnv { private String userdir = ""; private String userurl = ""; public UserEnv(){ userdir="aaa"; System.out.println("init userdir, one time"); } public...
各位大侠
帮个忙
cc.jsp:
Untitled
this is test2.jsp:
UerEnv.java:
package test;
public class UserEnv {
private String userdir = "";
private String userurl = "";
public UserEnv(){
userdir="aaa";
System.out.println("init userdir, one time");
}
public void setUserDir(String str)
{
userdir=str;
}
public String getUserdir() throws Exception{
return userdir;
}
}
我把cc.jsp放到D:Tomcat 4.1webappsexamplescc.jsp处
在examples的WEB-INFclasses目录下建立test文件夹里面
放编译后的UerEnv.class
输入:
http://localhost:8080/examples/cc.jsp
报错:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 0 in the jsp file: /cc.jsp
Generated servlet error:
[javac] Compiling 1 source file
D:Tomcat 4.1workStandalonelocalhostexamplescc_jsp.java:41: cannot resolve symbol
symbol : class UserEnv
location: package test
test.UserEnv myenv = null;
^
An error occurred at line: 0 in the jsp file: /cc.jsp
Generated servlet error:
D:Tomcat 4.1workStandalonelocalhostexamplescc_jsp.java:43: cannot resolve symbol
symbol : class UserEnv
location: package test
myenv = (test.UserEnv) pageContext.getAttribute("myenv", PageContext.SESSION_SCOPE);
^
An error occurred at line: 0 in the jsp file: /cc.jsp
Generated servlet error:
D:Tomcat 4.1workStandalonelocalhostexamplescc_jsp.java:46: cannot resolve symbol
symbol : class UserEnv
location: package test
myenv = (test.UserEnv) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "test.UserEnv");
^
3 errors
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:120)
……
请问各位大侠这是什么原因?
问题解决立刻给分
在线等
帮个忙
cc.jsp:
Untitled
this is test2.jsp:
UerEnv.java:
package test;
public class UserEnv {
private String userdir = "";
private String userurl = "";
public UserEnv(){
userdir="aaa";
System.out.println("init userdir, one time");
}
public void setUserDir(String str)
{
userdir=str;
}
public String getUserdir() throws Exception{
return userdir;
}
}
我把cc.jsp放到D:Tomcat 4.1webappsexamplescc.jsp处
在examples的WEB-INFclasses目录下建立test文件夹里面
放编译后的UerEnv.class
输入:
http://localhost:8080/examples/cc.jsp
报错:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 0 in the jsp file: /cc.jsp
Generated servlet error:
[javac] Compiling 1 source file
D:Tomcat 4.1workStandalonelocalhostexamplescc_jsp.java:41: cannot resolve symbol
symbol : class UserEnv
location: package test
test.UserEnv myenv = null;
^
An error occurred at line: 0 in the jsp file: /cc.jsp
Generated servlet error:
D:Tomcat 4.1workStandalonelocalhostexamplescc_jsp.java:43: cannot resolve symbol
symbol : class UserEnv
location: package test
myenv = (test.UserEnv) pageContext.getAttribute("myenv", PageContext.SESSION_SCOPE);
^
An error occurred at line: 0 in the jsp file: /cc.jsp
Generated servlet error:
D:Tomcat 4.1workStandalonelocalhostexamplescc_jsp.java:46: cannot resolve symbol
symbol : class UserEnv
location: package test
myenv = (test.UserEnv) java.beans.Beans.instantiate(this.getClass().getClassLoader(), "test.UserEnv");
^
3 errors
at org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandler.java:120)
……
请问各位大侠这是什么原因?
问题解决立刻给分
在线等
|
System.out.println("init userdir, one time");
可能要用
import java.io.*;
吧.如果不行,再在cc.jsp的页首加个试试
可能要用
import java.io.*;
吧.如果不行,再在cc.jsp的页首加个试试
|
我在RESIN下试的可以正确执行!结果是:this is test2.jsp:aaa
|
类UerEnv中添加package test;
之后重新编译
之后重新编译
|
你的UerEnv.class文件放到WEB-INF/classes/test里面没有
|
我试过了没有问题。
有点小问题就是文件名UerEnv.class应该是UserEnv.class的吧
有点小问题就是文件名UerEnv.class应该是UserEnv.class的吧
|
你用了package必须在classes目录下建立test(package名)目录。