• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how can I compile?

 
Derek Zeng
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two servlets: SetSessionAttributes & SessionAttrObject.
They are in the same package.
In the "SetSessionAttributes", it needs to use the object of "SessionAttrObject".
It compiles "SessionAttrObject" fine.
But when i compile "SetSessionAttributes", it says "cannot find SessionAttrObject".
Can somebody help me?
Thanks.
 
Bob CHOI
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally speaking, one servlet at compile time is independant of another because it merely relies on servlet api. The container at runtime takes the role to coordinate them.

Could you post your code?
[ January 10, 2007: Message edited by: Bob CHOI ]
 
Derek Zeng
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here are the codes:

SessionAttrObject.java
package webcert.ch04.ex0404;

import javax.servlet.http.*;

public class SessionAttrObject implements HttpSessionBindingListener {

private String data;

public SessionAttrObject(String val) { data = val; }

public String getData() { return data; }

public String toString() { return data; }

public void setData(String data) { this.data = data; }

public void valueBound(HttpSessionBindingEvent event) {
System.out.println(">B>B> valueBound() called for object " + getData());
}

public void valueUnbound(HttpSessionBindingEvent event) {
System.out.println(">U>U> valueUnbound() for object " + getData());
}
}


SetSessionAttributes.java
package webcert.ch04.ex0404;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class SetSessionAttributes extends HttpServlet {

protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

PrintWriter out = response.getWriter();
response.setContentType("text/html");
out.write("<HTML><HEAD>");
out.write("<TITLE>Binding Experiment</TITLE>");
out.write("</HEAD><BODY>");

String invalidate = request.getParameter("invalidate");

HttpSession session = request.getSession();
if ("true".equals(invalidate)) {
session.invalidate();
} else {
SessionAttrObject boundObject1 = new SessionAttrObject(
"Prometheus1");
SessionAttrObject boundObject2 = new SessionAttrObject(
"Prometheus2");
session.setAttribute("bound", boundObject1);
session.setAttribute("bound2", boundObject2);
session.setAttribute("nonBound", "Icarus");
session.setAttribute("bound", boundObject2);
session.setAttribute("bound", null);
}
out.write("<BR />Check console output to see what happened...");
out.write("</BODY></HTML>");
response.flushBuffer();
}
}
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use this command to compile :-



I will work fine (provided you're using Windows and the Tomcat directory mentioned is correct)

 
Derek Zeng
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is the same problem.
I put the SessionAttrObject.class and SetSessionAttributes.java in the same directory.
Should I put the CLASS file in another directory?
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just do this(instead of a big explanation--it's bound to work)==>
Make sure SetSessionAttributes.java and SessionAttrObject.java are in the same directory ....from the same directory use the following commands :-

Then copy the folder webcert and paste it under WEB-INF/classes...That's it
[ January 11, 2007: Message edited by: Sayak Banerjee ]
 
Derek Zeng
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works!
Thank you very much!
After compile the first file, it creats a subdirectory "webcert - ch04 -ex0404", and both two class files are in this folder. That's the problem.
 
Sayak Banerjee
Ranch Hand
Posts: 292
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
After compile the first file, it creats a subdirectory "webcert - ch04 -ex0404", and both two class files are in this folder. That's the problem.

Now what's the problem here?
Both the class files are supposed to be in the same sub-folder as they are in the same package.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic