??/出现了下面的错误,我得怎么样导包 ??/真够菜的。

z4b 2004-09-08 08:35:57
出现了下面的错误,我得怎么样导包 ??/

我设了
CLASSPATH=.;%JAVA_HOME%\lib;D:\tomcat\server\lib;D:\tomcat\struts\lib\struts.jar
Path=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\KAV6;C:\KAV2003;d:\Program Files\Real\Helix Producer Plus;C:\mysql\bin;D:\j2sdk\bin;D:\tomcat\bin;

JAVA_HOME=D:\j2sdk\

TOMCAT_HOME=D:\tomcat


D:\tomcat\webapps\sb-1\WEB-INF\src\sample>javac sampleaction.java
sampleaction.java:3: package javax.servlet does not exist
import javax.servlet.ServletRequest;
^
sampleaction.java:5: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletRequest;
^
sampleaction.java:7: package javax.servlet.http does not exist
import javax.servlet.http.HttpServletResponse;
^
sampleaction.java:22: cannot resolve symbol
symbol : class HttpServletRequest
location: class sample.SampleAction
public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServlet
Request request, HttpServletResponse response)
^
sampleaction.java:22: cannot resolve symbol
symbol : class HttpServletResponse
location: class sample.SampleAction
public ActionForward perform(ActionMapping mapping, ActionForm form, HttpServlet
Request request, HttpServletResponse response)

^
sampleaction.java:26: cannot resolve symbol
symbol : class SampleForm
location: class sample.SampleAction
if(form instanceof SampleForm)
^
sampleaction.java:30: cannot resolve symbol
symbol : class SampleForm
location: class sample.SampleAction
SampleForm theForm = (SampleForm)form;
^
sampleaction.java:30: cannot resolve symbol
symbol : class SampleForm
location: class sample.SampleAction
SampleForm theForm = (SampleForm)form;
^
Note: sampleaction.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
8 errors

D:\tomcat\webapps\sb-1\WEB-INF\src\sample>
...全文
242 点赞 收藏 29
写回复
29 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
z4b 2004-09-10
用这个命令 javac *.java
就可以全部编译 生成 .class文件
出现一个信息:
Note:RegisterAction.java uses or overrides a deprecated API.

Note:Recompile with -deprecation for details.

如果一个.java 文件一个的编译,到 RegisterAction.java 就出现

D:\tomcat\webapps\sb-1\WEB-INF\classes\app>javac registeraction.java
registeraction.java:12: cannot resolve symbol
symbol : class RegisterForm
location: class app.RegisterAction
RegisterForm rf = (RegisterForm) form;
^
registeraction.java:12: cannot resolve symbol
symbol : class RegisterForm
location: class app.RegisterAction
RegisterForm rf = (RegisterForm) form;
^
registeraction.java:20: cannot resolve symbol
symbol : variable UserDirectory
location: class app.RegisterAction
UserDirectory.getInstance().setUser(username,password1);
^
registeraction.java:22: cannot resolve symbol
symbol : class UserDirectoryException
location: class app.RegisterAction
} catch (UserDirectoryException e) {
^
Note: registeraction.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
4 errors
D:\tomcat\webapps\sb-1\WEB-INF\classes\app>

这个错误信息。 郁闷 真么回师?
回复
z4b 2004-09-10
package app;

没有文件开头都是导入这个包.
回复
yaray 2004-09-10
这几个Java文件都需定义包名为app
package app;

编译: javac *.java
回复
z4b 2004-09-10
楼上说的 import app.RegisterForm;
??
回复
yeshucheng 2004-09-10
你的这个action是没有错误,但是在你的import中怎么没有看到RegisterForm 的导入呢?
回复
z4b 2004-09-10
RegisterAction.java 代码如下: 就是 struts in action 的第一个例子 ./

package app;

import org.apache.struts.action.*;
import javax.servlet.http.*;
import java.io.*;
public class RegisterAction extends Action {
public ActionForward perform (ActionMapping mapping,
ActionForm form,
HttpServletRequest req,
HttpServletResponse res) {
// ①Cast the form to the RegisterForm
RegisterForm rf = (RegisterForm) form;
String username = rf.getUsername();
String password1 = rf.getPassword1();
String password2 = rf.getPassword2();
// ②Apply business logic
if (password1.equals(password2)) {
try {
// ③Return ActionForward for success
UserDirectory.getInstance().setUser(username,password1);
return mapping.findForward("success");
} catch (UserDirectoryException e) {
return mapping.findForward("failure");
}
}
// ④Return ActionForward for failure
return mapping.findForward("failure");
}
}
回复
z4b 2004-09-10
老大, 我现在的问题是无法识别同目录下的包.例如:
app 文件夹有下列文件:
RegisterForm.java
UserDirectory.java
UserDirectoryException.java
RegisterAction.java
前面3个都可以正常编译,可是到了RegisterAction.java 出现下列错误:
D:\tomcat\webapps\sb-1\WEB-INF\classes\app>javac registeraction.java
registeraction.java:12: cannot resolve symbol
symbol : class RegisterForm
location: class app.RegisterAction
RegisterForm rf = (RegisterForm) form;
^
registeraction.java:12: cannot resolve symbol
symbol : class RegisterForm
location: class app.RegisterAction
RegisterForm rf = (RegisterForm) form;
^
registeraction.java:20: cannot resolve symbol
symbol : variable UserDirectory
location: class app.RegisterAction
UserDirectory.getInstance().setUser(username,password1);
^
registeraction.java:22: cannot resolve symbol
symbol : class UserDirectoryException
location: class app.RegisterAction
} catch (UserDirectoryException e) {
^
Note: registeraction.java uses or overrides a deprecated API.
Note: Recompile with -deprecation for details.
4 errors
D:\tomcat\webapps\sb-1\WEB-INF\classes\app>
我就是象您说的那样设置的各个量./
回复
yaray 2004-09-10
JAVA_HOME=D:\j2sdk <--没有反斜杠,也没有分号(到目录名为止什么也不应该有)

TOMCAT_HOME=D:\tomcat <--4.0版本之前设置这个
CATALINA_HOME=D:\tomcat <--4.0版本之后设置这个

CLASSPATH=.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar;D:\tomcat\server\lib;D:\tomcat\struts\lib\struts.jar

Path=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;C:\KAV6;C:\KAV2003;d:\Program Files\Real\Helix Producer Plus;C:\mysql\bin;D:\j2sdk\bin;D:\tomcat\bin;.;



回复
dropship 2004-09-10
classpath用一定要有.;这个部分,.表示当前目录
回复
yaray 2004-09-10
如果已经全部都定义相同的包名,那么同包内的类之间的互相引用是不需要import的.

既然已经可以用javac *.java了,为什么还要单个地进行编译?

Note: registeraction.java uses or overrides a deprecated API.
提示你使用或覆盖了不赞成使用的方法.(:::有可能在以后的JDK中不再支持这个方法:::)
回复
z4b 2004-09-09
http://community.csdn.net/Expert/topic/3353/3353720.xml?temp=.9000208

各位老大帮忙.谢谢
回复
yaray 2004-09-09
看样子你的这两个类都定义了包名为sample,所以不需要import就可以直接使用对方.

同包名下的java文件编译: javac *.java
回复
zhaohh 2004-09-09
哈哈,跟我的一样,不过后来我解决了,那就是用了 jcreator就可以了
回复
viano 2004-09-09


你的 javax servlet 包有问题

你看看 到底有这个包

估计没有 !

你可以在 jbuilder 里面的 thirdparty 的tomcat 里面找到这个包

放在你的应用程序 web-inf 下面的lib 就可以了

或者 在

用:classpath 指向这个包!
回复
z4b 2004-09-09

viano(我爱十三妹子)
老大 我按照你说的 设置 了 还是原来的错误,怎么回师呢?

QQ: 13628198
回复
z4b 2004-09-09
z4b@163.com 谢谢各位老大。
回复
fantasyCoder 2004-09-09
留下邮箱,我发给你点资料...
回复
viano 2004-09-09


path

D:\j2sdk\bin
回复
viano 2004-09-09


classpath

.;D:\j2sdk\lib\tools.jar;D:\j2sdk\lib\dt.jar;
回复
bluesky35 2004-09-09
首先,设置好CLASSPATH,将所有的包(JDK和TOMCAT)都设置进去,也可以用javac -classpath <path>方式指定.
第二,先编译SampleForm.java,将编译出来的CLASS文件放在sample下,然后用javac -sourcepath <path>编译.
回复
加载更多回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-09-08 08:35
社区公告
暂无公告