~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

A lot of complicated terminology being thrown around here but a few points:

> A static member of a class is a shared location in memory between objects of that class.

Don't mix concepts and implementation details when explaining. From the JLS:

If a field is declared static, there exists exactly one incarnation of the field, no matter how many instances (possibly zero) of the class may eventually be created. A static field, sometimes called a class variable, is incarnated when the class is initialized

> static values are resolved at compile time, before objects are created.

A compile time constant expression when assigned to a static field[or not] is evaluated at compile time; a static field is incarnated when the class is initialized. There is no *static value*.

> Notice that in main of a different class file, I didn't need to create an object of MyClass in
> order to access sharedInt - the address of the reference-variable sharedInt is resolved at
> Compile Time and all MyClass objects have access to it.

`sharedInt' is a variable of Primitive Type and not Reference Type.

> If q is not a static member, then although each C class object has q, they have their own
> individual address for their reference variable and therefore

Each instance created has its own set of the state/member variables. There is no *individual address for their reference variables*.

> to access q …

Alex Edwards commented: Thanks for pointing that out @_@ +4
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Use a better development environment like Firefox along with Firebug installed to look out for Javascript errors. If there are no errors, paste the entire code as it is here along with the changes incorporated. The description `doesn't work' is as useless as it can get.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> even after doing the above changes my problem persists.

Like I have always mentioned in this thread, the intermittent problem isn't related to Javascript; it's just that I pointed out some mistakes and you fixed them.

> by the way could it be that my tomcat web server is denying page requested to that
> particular client?

Without any logs [application/tomcat], there is no way we can help you out. Get an expert to look at your network config / Tomcat installation.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

You need to provide a default constructor for the `Circle' class. Also, since `main' method is `static', you can't access instance variables inside it. It wouldn't make sense to access something which pertains to the state of a `Circle' inside a method which can be invoked without a `Circle' instance. Also consider using Math.PI instead of rolling in your own unless you have a good reason to do so.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

What about the first two questions? What return value do you get?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Since you are using a forward, there is no need to use session variables. The HttpServletRequest is preserved when forwarding.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Add this to the page that URL1 points to:

window.location = url2; //the url you want to redirect to.

The `location' property of `window' object is itself an object but you are assigning a string to it. Though it *works*, it's incorrect. You need to set the href property of the location object.

window.location.href = 'http://www.google.com/';

> I want to redirect a certain URL to another URL.

A better solution here would be to employ URL Rewriting; look into the mod_rewrite module of Apache Web server. Your solution fails if Javascript is disabled.

@scru
Concerning your rep comment given to `stultuske', consider the possibility of this thread originally being posted in some other forum and then being moved here.

scru commented: Didn't know. Usually they have moved: on them. Apologies. +4
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Is the connection in autoCommit mode? If not, then you need to explicitly commit the transaction. Check the return value of the executeUpdate ; is it 1?

Does a standalone program which inserts some sample data in the table works?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> i want to trace these button events.

You can't trap this event.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> does the Servlet Container call the destroy() method of a servlet class even if we don't
> define the destroy() method in Servlet?

Yes, because it inherits one from GenericServlet.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> And it worked. Although the file saved in my file system has extension .gif ??

The file name doesn't matter; its content does. I could have very well named it 'image.exe' and it still wouldn't have mattered. Maybe you overlooked the declaration File saveFile = new File("SemiTransparentSquare.gif"); in which the file name is pretty much a constant.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The thing you fail to realize here what seems to be a *slight adjustment* or *subtle* to you isn't that *subtle* to the program. Maybe what you are looking for is fuzzy comparison which IMO doesn't make sense when comparing binary files; it would work pretty good for text files. You need to apply techniques like finding the distance between two string sequences; read this. Be warned though, the implementation for this definitely won't be a trivial one.

HTH,
sos.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Consider using code tags to post your code next time. Read the FAQ's.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> I've been able to find plenty of examples of Ajax being used to display data from XML on
> a web page

XML when served by the server when making asynchronous requests is purely for the sake of easy data manipulation given that a XML response can be easily inspected/worked upon using the DOM API.

> but I haven't found many examples of Ajax being used to update/edit the content or
> structure of an XML file through the web page front-end

You can, but there doesn't seem to be any real need to do so.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> its contents may vary slightly but are essentially the same.

Define *essentially the same* in a unambiguous manner. To prove how lost the above statement is consider three files:

There is a lot of ambiguity in what you say.

There i a lot of ambiguity in what you say.

There is a lot of ambiguity in what you think.

Do you think they are *slightly* different? How would you go about actually proving it?

> license.txt files for recently installed applications come ups as duplicates on my program
> when using the file.getName() for comparison

If your aim is content comparison, checking the file names / path is kind of pointless since a directory can't have two files with exactly the same name.

> So CRC32, Adler32, or MD5 checksums will not work for you?

Given his definition of comparison it won't since they aim for an exact match of contents.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> The comparison needs to be so robust that even if duplicate files exist with slight changes

You use the word `robust' in the wrong context here; the implementation would be robust if it picks up even the smallest of changes in the file. The thing you are looking here for is approximation based comparison.

> Do you know what the hashCode() method of the file class computes on a Mac?

Most probably the hashCode of the return value of File#getPath ORed with some random number. But that's besides the point since hashCode computation has got nothing to do with the file contents.

> I suppose the reading byte by byte may be the solution, if more than half the bytes are
> identical one may assume the file is the same.

This really doesn't make any sense. What exactly are you trying to achieve here?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> They will only change it for you once, if you have a good reason and are nice to them.

If you will notice, it is already done.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> i heard some compilers like Eclipes

Eclipes [sic] is not a compiler but an IDE.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

AFAIK, the implementation of hashCode() and equals method of File class depends on the underlying file system. On Windows files systems, the hashCode() method of the File class is actually the hash code of the result of getPath() after converting it to lowercase. The equals() method compares the result of getPath() ignoring its case. Since path names in *nix systems are case sensitive, the implementation might adjust itself accordingly.

The way this problem can be approached depends on what kind of a comparison are you looking for. If you actually want to compare the file contents, you are stuck with byte by byte comparison [as suggested by masijade] or computing and comparing the md5 checksum of both the files.

If Java is not a mandate, I am sure there are better platform specific ways of doing this.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Please suggest me a solution to solve this problem.

A simple google search would have solved it for you; please consider searching the web/forum archives before posting a query. Anyways, read this and this.

> If there is any other way to handle this scenario please suggest me the better way.

Two ways come to mind: Either use the executeBatch functionality provided by the JDBC API or push those five queries into a stored procedure which, when blows up brings down the entire transaction.

> And you're real problem, at least IMHO, is using the JDBC-ODBC in Tomcat.

I don't think he is using a bridge type driver given the package name com.microsoft.jdbc.* and [Microsoft][SQLServer 2000 Driver for JDBC] .

> The bridge is not threaded and Servlets/JSPs are.

I really don't see how this is different from the way threading is handled in Java I/O classes which do make native calls; the threading is most probably handled in the Java implementation of JdbcOdbc. Some real problems with ODBC implementations are invoking third party native code, installation required on the client machine, debugging nightmares etc. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> where must i put the throw Exception,if i haven't had the file saver.txt????

If you don't have ``saver.txt'', it will automatically be created given that sufficient privileges are available.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> var http = new ActiveXObject("Microsoft.XMLHTTP");

The way you create the XHR (XMLHttpRequest) object is IE specific and won't work on other browsers / operating systems. Use some Ajax library to ease your task.

> how should i write the code> i did not get you?

You need to encode the data you send to the server. Hence:

var params ="save="+save+"&s1="+ans+"&s2="+tot+"&s3="+y+"&s4="+n;

// the above needs to be replaced with
var params ="save=" + encodeURIComponent(save) +
                    "&s1=" + encodeURIComponent(ans) +
                    "&s2=" + encodeURIComponent(tot) +
                     "&s3=" + encodeURIComponent(y) +
                     "&s4=" + encodeURIComponent(n);

...so that the data *really* is encoded.

> do u think my problem could be Internet explorer specific?

It surely isn't related to Javascript if that's what you want to know.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

i am not asking for coding. I am just asking that whether my inorder traversal of the binary tree is right?

The inorder traversal i have gotten is
IBOMLQAFNSGZFHYXRKPWZVT

Thanks

That isn't a binary tree given that nodes B, F and H have more than two child nodes. If you don't have a Java question, would you like me to move this to the Computer Science forum?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Make sure your SELECT elements have a name attribute which can be then used to retrieve the selected value using ServletRequest.getParameter in case only single selection is allowed or ServletRequest.getParameterValues in case multiple selections are allowed.

Don't use JSP's for anything other than presenting the data; use servlets for handling form submissions.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Is this even a Javascript question given that what you have posted seems like PHP? If you want to manipulate cookies using Javascript, read this. If this really is a PHP question, allow me to move it to the PHP forum.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> I am not sure, why the method is returning null! Any idea?

Strange. AFAIK, System.getSecurityManager returns null when there is no SecurityManager for that given application i.e. no security context exists.

BTW, which version of Java are you using? Which OS? Does it have multiple user accounts? When booting up your OS are you asked to authenticate yourself?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

A useful reply can be provided only when we set a proper context here. Read the closure notes.

Now, what do you think those two do? What differences do you see in them? Do they end up solving the problem at hand?

Hint: Both approaches don't do what they were intended to.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Your description here gives an indication that this might be a configuration / network issue rather than having something to do with Javascript as such.

> i am blocking till a reponse is returned because if the answers is not saved due to a
> server error i do not want the students to write further and waster their time.

And what happens when a server error occurs in your case? You anyways have to code a way around or handle the contingency be it synchronous / asynchronous calls. A better way would be to check the status of the asyn call and handle the different conditions accordingly.

> i thought this line is for url encoding the data. i mean i want the students to be able to
> type "&" in their answers. this was not possible earlier when i was using GET request.

Is it possible now? Are you able to send answers having characters '&', '=' and '?' ? Without an encoding in place for the user data, the answers would be sent as they are thereby causing unexpected effects at the server. Try it.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> is throwing Exception (not SecurityException). Hence, something is going wrong with the
> code.

Then you need to let us know which exception is that along with the *complete* stack trace as it is since it is kind of difficult to reproduce the exact environment/settings you have at your place.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Am I Missing any thing here? Any suggestions are appreciated.

The fix suggested by Masijade should work out for you; but just for the record, the way you are using SecurityManager in your code doesn't seem to be right.

The security manager needs to be aware of the environment / context to which it needs to apply security checks. By calling the SecurityManager constructor, you just create a new SecurityManager instance, not a security manager which is context aware. Use the System.getSecurityManager() to grab an instance of environment aware SecurityManager.

// unstested
import java.io.File;

public class SecurityTest {

  public static void main(final String args[]) {
    doSecurityTest();
  }

  private static void doSecurityTest() {
    SecurityManager sm = System.getSecurityManager();
    File roots[] = File.listRoots();
    for(int i = roots.length - 1; i >= 0; --i) {
      String root = roots[i].toString();
      try {
        sm.checkRead(root);
        System.out.println("I have read access to " + root);
      } catch(SecurityException se) {
        System.out.println("I don't have read access to " + root);
      }      
    }
  }

}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

But how is this related to Java? If you have a Java program which doesn't behave as expected for the above problem, post it, otherwise I would be moving this to the Computer Science sub-forum.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

The size attribute of the SELECT element does exactly that; instead of ruining the user experience by dropping down the entire list contents, it shows only `size' elements.

<select name="sel" size="2">
  <option value="one">1</option>
  <option value="two">2</option>
  <option value="three">3</option>
  <option value="four">4</option>
  <option value="five">5</option>
  <option value="siz">6</option>
</select>

If this is not what you desire, you need to post a screen shot or at least a link to the concerned output.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Is there a better way? There are actually many more than three subclasses that need the
> special handling, so that's a long if-else if-else statement.

Just create an interface Collidable which exposes a contract of the form Outcome collide(Collidable c) . Make classes implement this interface and implement the logic accordingly, which, based on the source and target colliding objects would determine the outcome of the collision. No need for any run-time type checks, the run-time method invocation based on the actual object in consideration will be automatically taken care of.

> You could use a State Machine, or State Pattern based on how many times an object has been
> encountered, or the State of an object can depend on the type of object it encounters...

KISS ;-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Can it be something to do with the @ sign?

Yes.

Make sure you *always* encode user entered data; at least when making asynchronous calls using Ajax. Normal submits automatically encode the form data for you. Use encodeURIComponent.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It can be done using HTML only; just use the `size' attribute of the SELECT element.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> if i use a different domain name then it works but not otherwise,

What do you mean by it works when using a different domain? Does using the complete URL instead of just 'storeSubject.jsp' seem to work? I can't think of any problems with code which might cause this issue; it either works or it doesn't. Do the web servers logs show anything?

> http.open('post', 'storeSubjective.jsp',false);

Why are you making synchronous calls? Do you really want to block till a response is returned from the server?

> http.setRequestHeader("Connection", "close");

Not necessary, drop it.

> http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

You have this yet you end up not encoding the data?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
out.print("\n");

out.print(System.getProperty("line.separator")); or just make the OP use the BufferedWriters ' newLine() method.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> ok so if i mark this as solved , will this be enough for you to stop?

If you feel you have got your answer, please do so.

One of the tricks I normally suggest to people looking for project ideas is to head over to some open source project repository [sourceforge, freshmeat] and browse projects of any alternative language you would be interested in learning or have worked with in the past. Porting projects is more fun that you can imagine and you end up with having a copy of the source code just in case you are stuck with the implementation.

Another trick would be to observe the things around you which you use on a daily basis. Ever used Eclipses' code formatting, how about creating one for Java. Don't like your download manager, how about creating your own customized one?

I am pretty sure that with these you might never need to ask anyone about project ideas anymore.

On a final note, please remember that when you post a thread, the people replying to it invest their valuable time when trying to help you out. Your replies might just make the difference in having a healthy debate and a flame war.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Pure Java solutions / libraries for converting videos to different formats might be a bit hard to get by. There are a lot of open source / free converters out there [like ffmpeg] which you can use in conjunction with your application to achieve the desired task since re-writing the entire thing in Java would be a significant act.

One of the ways to do it:
• Use your web application as a front end for allowing users to upload their videos.
• When storing the videos, either store them directly to your File system or use a Database; depends on how your project is engineered.
• Run a background process which would pick up the file from a specified directory, convert it and put it in another directory [or table if using Database].
• The background process would run a command line version of the file conversion utility for converting files.

Another way would be to create a thin wrapper around the open source libraries out there which are written in C or C++ and make native calls using JNI.

But on a final note, this is by no means a simple project and having an architect on your team who *knows* things really helps.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

It's not pretty clear what you mean by the `First Node' since there is nothing of that sort in your program. What are the specifications of the LinkedList you are trying to create here? Without having an inking of how things ought to be, helping you out would be difficult.

By the way, take a look at the source code of LinkedList which comes along with your JDK; it might just help you.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> [snip]
> How do I get it to only add on the next line?
> [snip]
> Or is there a simpler way?

Thoroughly reading the documentation would help you in the long run. :-)

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

He just pointed out that you multi-posted, try not to get personal here.

If the problem here is program logic, post in the Computer Science and Software design forum. If you feel like posting the same question in different language forums, at least post a link to your original thread so that people don't end up discussing the same things over and over again.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Your solution can be roughly broken into the following tasks:

- Design a web page as per your requirement
- Attach a listener to the key handler which monitors keystrokes pressed inside the search text box.
- In that listener, create a XHR (XMLHttpRequest) object which asynchronously polls the server script [JSP/PHP/Perl etc.] with the data entered by the user with the response being all the possible choices for the given keyword. Use XML / JSON as your data format for shipping data.
- With the data received from the server, create a dynamic DIV which will be placed below the text area displaying all the possible choices in a list. [Rendered using a TABLE or Ordered List / Unordered List]
- Rinse and repeat.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> Does anyone know of a way to make it so the customer can click a link to start the game
> instantly without haveing to [download-save-open] the file...

No, it can't be done. Isn't the reason apparent here? You go to a site, click on a link which actually hooks to a virus, the browser runs the executable without asking for a confirmation...

Go with Langsors' advice; Flash is by far the most used/safe format for distributing games on the web.

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Ummm I have been testing it and been using /[^0-9]/ .

The code will only allow me to type in 0-9.

If I remove the ^ it allows me to type anything but 0-9.

Am I doing something wrong?

Sorry, Thanks for the help.

Are you sure you are doing it the right way. In Javacript console of Firebug:

/[^0-9]/.test("a")
true

/[^0-9]/.test("9")
false

What is the environment in which you are testing these regexes?

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

int x=10;
int total=10;
do {
total += x++;
}while(x<15);
System.out.println(x);

The output of this program will be 15. I don't understand why 15 is the answer.

I'm not understanding the arithmetic here. Doesn't the "+=" mean total = total + x? And doesn't x++ mean that the next value for x will be x+1?

I don't see why this would not output 20 on the first go around. 21 on the second go around, etc.

A rewrite:

int total = 10, x = 10;
do {
  total = total + x;
  x++;
} while(x < 15);
System.out.println("x -> " + x);

Output: x -> 15
int total = 10, x = 10;
do {
  total = total + x;
  x++;
  System.out.println("total -> " + total);
} while(x < 15);

output:
  total -> 20
  total -> 31
  total -> 43
  total -> 56
  total -> 70

Hope you do realize what you are doing wrong here...

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

I guess this is because your last two Readers end up using the same underlying stream to read from the source; here file . Because of this, when the third BufferedReader finishes, the end of stream has already being reached for the file and further reading obviously returns null .

Either create a new instance of the FileInputStream for each Reader or reset the stream marker as soon as you are done reading once.

A few observations though:
• You need not make Readers/Writers instance variables since they logically don't form the `state' of your SpellChecker; plus its always better to declare variables at the point of use and persisting BuferedReader serves no purpose here. The same is the case with `i' and `j'; they form a part of your implementation and need not be made instance variables.
• Creating a File instance the way you have done is also *bad*.
• Your code does not close all the open resources.
• Even though this looks like a prototype, try to organize your thoughts and implementation rather than dumping them together.
• When pasting code, make sure you convert tabs to spaces since the rendering of tags is not consistent across implementations. [your editor might render a tab as 2 spaces while this message board might use 8 spaces].

~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Bzzt, that should be enough; I request the people posting here to post on topic and not let the sentiment with which the OP started the thread to be diluted by pointless arguments.