struts的类库怎么找不到呢?
我下载了struts1。1的库,但是引用它的库做了一java文件进行编译后,老是提示找不到这个库,如下所示:
D:\tomcat\webapps\struts-example\WEB-INF\src\org\apache\struts\webapp\example\SaveRegistrationAction.java:68: package javax.servlet does not exist
不知道什么原因,还有就是javax的包也找不到,请各位大侠指点一下。
问题点数:0、回复次数:6Top
1 楼elathen()回复于 2004-09-03 18:26:46 得分 0
如果用javac来编译的话,你要把servlet.jar这个包加的classpath路径中去.Top
2 楼charlie0895(命----世上本没有路,我多走几次也就成了路.... )回复于 2004-09-03 18:31:21 得分 0
这个应该你里的配置文件的问题,还有你文件放的目录有问题吗!
要不我先给给简单的例子,你看看有什么疑问吧!
index.jsp:
<%@ page language="java" contentType="text/html; charset=GB2312" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html:html>
<body>
<table>
<html:form action="Member" name="MemberForm" type="struts.MemberForm">
<tr>
<td>姓名:</td>
<td><html:text property="name"/></td>
</tr>
<tr>
<td>密码:</td>
<td><html:password property="password"/></td>
</tr>
<tr>
<td><html:submit value="提交"/></td>
</tr>
</html:form>
</table>
</body>
</html:html>
Action:
package struts;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class MemberAction extends Action {
public String getQuote(HttpServletRequest request, String name, String password){
String qq = null;
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
DataSource data = null;
try{
data = getDataSource(request);
conn = data.getConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery("select * from member where "+"net_name='"+name+"' and "+
"password='"+password+"'");
if(rs.next()){
String s = "";
s = rs.getString("e_mail");
qq = new String(s);
System.err.println("qq:"+qq);
}
else{
System.err.println("Name not found returning null");
}
}
catch(SQLException e){
System.err.println(e.getMessage());
}
finally{
if(rs != null){
try{
rs.close();
}
catch (SQLException sqle){
System.out.println(sqle.getMessage());
}
rs = null;
}
if(stmt != null){
try{
stmt.close();
}
catch(SQLException sqle){
System.out.println(sqle.getMessage());
}
stmt = null;
}
if(conn != null){
try{
conn.close();
}
catch(SQLException sqle){
System.out.println(sqle.getMessage());
}
conn = null;
}
}
return qq;
}
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException,ServletException {
/**@todo: complete the business logic here, this is just a skeleton.*/
String s = null;
String target = new String("success");
if(form != null){
MemberForm memberForm = (MemberForm)form;
String name = memberForm.getName();
String password = memberForm.getPassword();
s = getQuote(request,name,password);
}
if(s == null){
target = new String("failure");
}
else{
request.setAttribute("PRICE",s);
}
return (mapping.findForward(target));
}
}
Form:
package struts;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
public class MemberForm extends ActionForm {
private int id;
private String name = null;
private String password = null;
private String real_name = null;
private String sex = null;
private String e_mail = null;
private String qq = null;
private String descri = null;
public int getId(){
return id;
}
public void setId(int id){
this.id = id;
}
public String getName(){
return (name);
}
public void setName(String name){
this.name = name;
}
public String getPassword(){
return (password);
}
public void setPassword(String password){
this.password = password;
}
public String getRealName(){
return (real_name);
}
public void setRealName(String real_name){
this.real_name = real_name;
}
public String getSex(){
return (sex);
}
public void setSex(String sex){
this.sex = sex;
}
public String getEMail(){
return (e_mail);
}
public void setEMail(String e_mail){
this.e_mail = e_mail;
}
public String getQq(){
return (qq);
}
public void setQq(String qq){
this.qq = qq;
}
public String getDescri(){
return (descri);
}
public void setDescri(String descri){
this.descri = descri;
}
public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
this.name = null;
this.password = null;
this.real_name = null;
this.sex = null;
this.e_mail = null;
this.qq = null;
this.descri = null;
}
}
quote.jsp:
<%@ page contentType="text/html; charset=GB2312" %>
<html>
<head>
<title>
qoute
</title>
</head>
<body bgcolor="#ffffff">
<table width="500"
booder="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<h1><%= request.getAttribute("PRICE")%></h1>
</td>
</tr>
</table>
</body>
</html>
Top
3 楼yeshucheng(叶澍成★七哥)回复于 2004-09-03 18:41:30 得分 0
呵呵,先建议下楼上的对于actionFormBean的写法问题:
以后在设置参数时最好不要写:this.xxx=xxx;虽然这样写完全可以,但是你要注意一旦你少写了前面的this后果就要得到null,呵呵。所以最好还是在参数前写个'a'为好
以上只是个人意见Top
4 楼XIHSHI(西红柿)回复于 2004-09-03 19:15:40 得分 0
估计你有两个servlet.jar
UPTop
5 楼ha791228(王小虎)回复于 2004-09-03 19:52:41 得分 0
谢谢大家的回复,我在classpath路径下添加了D:\tomcat\common\lib\servlet.jar文件,但还是不行啊,老是提示javax.servlet包找不到。我也安装了Jbuilder,会不会和楼上所说的有两个servlet.jar冲突,谢谢大家!Top
6 楼louisqiang(tenwin)回复于 2004-09-04 01:04:38 得分 0
老兄:我记得好象是servlet-api.jarTop




