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

Nick did a good job of coming up with the approximate formula used when deriving rep:

This is how I figured it's sort of working; you get +1 power for:

  1. each year of membership
  2. every ~1000 posts
  3. every ~500 reppoints
  4. negative rep power is half your +power with floor-rounding

.

The entire thread here (Area 51).

Lusiphur commented: I know it doesn't work in feedback but, it's the thought that counts right? +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Only form values are submitted when you press the submit button of the form. You need to place your form controls (text inputs, combo boxes, radio buttons) inside your form control for the values to be submitted to the server.

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

No offense, but if you had read the posts over I did indeed give a short explanation of what I was having issues with. I do agree that my first code was a bit long, but the second one is as short as I can manage to make it.

No offense, but did you even read the link I posted? The second 'C' in SSCCE stands for compilable code which none of your posts contain. When posting queries/issues, try to phrase the question such that the person trying to help you out has to exert the least effort. Things like "i was hoping you'd understand" wastes my as well as your time. Anyways, after trying really hard to make out what you want, here's what I think.

You can't cast Arraylists the way you are trying to do. This is because generics in Java don't exhibit the covariance property shown by arrays. When dealing with arrays, T[] can be assigned to S[] if S is the super-type of T. The problem in this case is that you might end up putting elements in an array of a type which don't belong to that array which blows up at runtime (not compile time).

Integer[] ints = new Integer[] { 1, 2 };
Number[] nums = ints; // ok
nums[1] = 1.23;  // runtime exception

Generics on the other hand are invariant i.e. List<T> can't be assigned to List<S> unless both S and T are the same. Covariance can be …

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

Hovering over the graph gives you the number of posts posted for each month, but yes, the ability to display reputation received is still not present AFAIK.

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

Just flag the same post again requesting it to be ignored, should do the job IMO.

Also, the flag bad post isn't in any way related to the age of the thread/post. If a member finds something inappropriate with a year old thread (spam/other violation), reporting it makes sense though practically speaking this isn't a regular occurrence. Spam posted in 1999 is still spam in 2010, if you know what I mean. :-)

Lusiphur commented: Ya, I know, feedback forum = no rep but still! +0
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

> b = (one)a;

`b` and `a` are of reference type ArrayList but you are trying to cast them to type `one` and hence the error.

BTW, instead of posting large code snippets it would be better if you explained "what" you wanted to do and a small code snippet which demonstrates the exact problem you are facing. Read SSCCE.

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

> Can anyone tell me how to use new Instance and what mistakes i
> have made in this program.? newInstance is actually a method of the Class and Constructor classes. You need to grab the class instance to invoke this method.

package com.you;

public class Test {
  public static void main(final String[] args) throws Exception {
    Test t = null;
    t = Test.class.newInstance(); // by hardcoding the class name
    // OR
    t = Class.forName("com.you.Test").newInstance(); // load class from name
  }
}

If you need to pass in arguments when creating a new instance, grab the relevant constructor and then call `newInstance` on it.

package com.you;

public class Test {

  public Test(String name) {
    System.out.println("Called string constructor");
  }

  public static void main(final String[] args) throws Exception {
    Constructor<Test> con = Test.class.getConstructor(String.class);
    Test t = con.newInstance("your-name");
  }
}

> Thank you in advance

HTH :-)

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

Don't use JSP's for placing your business logic; use Servlets instead for your redirection purposes. Also, for performance reasons, before going in production make sure you replace the logic of grabbing connection directly from the DriverManager class with getting connection from a connection pool.

Coming to your code, you need to actually "execute" the SQL statement you created to get the file name. Read the JDBC tutorial on how to go about doing this.

A rough structure of your code should be something like:

// Servlet Class
public class ElearningServlet extends HttpServlet {
	
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
		Course course = createCourseFromRequest(req);
		ElearningDao dao = new ElearningJbdcDao(ConnectionUtils.getDatasource());
		String fileName = dao.getFileNameForCourse(course);
		// sanitize name for making it uri compatible if required
		response.sendRedirect("http://www.something.com/course/" + fileName);
	}
}
// Value object Course
public class Course {

	private String courseId;
	// getters and setters

	// other fields
}
// DAO interface
public interface ElearningDao {
	public String getFileNameForCourse(Course course);
}
// DAO implementation
public class ElearningJdbcDao {
	private Datasource;
	
	public ElearningJdbcDao(Connection connection) {
		this.connection = connection;
	}
	
	public String getFileNameForCourse(Course course) {
		String statement = "SELECT document_filename from x_masterlistofdocuments where course_id=?";
		Statement stmt = null;	// prepare statement using the connection
		// set the placeholder value using the `course` object using `course.getCourseId()`
		ResultSet rs = null;	// execute statement
		String name = null;	// read the name from the resultset
		return name;
	}
}

Of course, the example code above is …

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

What do you mean by "doesn't work"? Exception? No result? Anyways, have you tried passing in an Object array as shown in the official documentation? Paste the code you are using.

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

This is purely a client side issue and can be done in Javascript; read this. If you want to do it at the server side without any delay, look into the method HttpResponse#sendRedirect .

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

I've already explained it in my previous post; also read this.

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

Did you try out the suggestion in my previous post?

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

Most likely the Ajax result is being cached; append a random tidbit to your URL, preferably something like timestamp to have a distinct URL for each request to prevent this caching. If you are using an URL like /YourApp/Upper append it with /YourApp/Upper?t=timestamp .

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

> So you mean to say I'm lying ?

*facepalm*; sarcasm detection.....failed. :-)

> Its surely not anything to do with latest FF release

A couple a things we'd like to confirm:
- Have you tried flushing the browser cache?
- Does this happen only with *nix + FF or with *nix + any browser?
- Does programmingforums look the same way?

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

doGet method maps to the code executed when your servlet receives a "GET" HTTP request. doPost method maps to the code executed when your servlet receives a "POST" HTTP request. These methods are internally called by the `execute` method of your servlet (a lifecycle method) based on the HTTP method of the request received.

If you have specifically created a servlet which handles only POST requests (uploading etc.), you'd normally override the doPost method. Any other HTTP method used to access your servlet would result in a "method not supported" exception (well technically it isn't *any* other method but you can ignore the difference for the time being).

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

> But, whenever derived class object is created, memory is assigned to base class
> members too

Yes, memory is assigned for all those member variables of the base class but there is no *separate* base class object created. The fields and methods which can be inherited are *inherited*. When you extend an existing class, you end up with a class which has everything that the super class has along with the members/methods declared for your new class. AFAICT, the concept of super classes is just a logical abstraction language designers have come up with to facilitate re-use, polymorphism etc. Also, why should an object of class A be created when I have specifically asked the runtime to create an object of class D?

> we can access the base class fields using super. Isn't super a reference to the
> base class object

A quick quiz; what does the following snippet print:

package gone.to.heaven;
class MyClass {
  public static void main(final String[] args) {
    MyClass c = new MyClass();
    System.out.println(c.superToString());
    System.out.println(c.toString());
  }
  public String superToString() {
    return super.toString();
  }
}

In case you were wondering, it prints the same thing both the times which is gone.to.heaven.MyClass@123456 .

Another quick quiz; does the following piece of code compile?

class MyClass {
  public void doSomething() {
    Object obj = super;
  }
}

No, it doesn't, because there is *no* `super` object which can be assigned to `obj`. `super` is a language feature/abstraction which …

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

To find out which JAR a given class belongs to, use a service like GrepCode. It tells you all the possible JAR files which has that particular class along with providing download for the same. For e.g. here's the grepcode result for the JAR file which uses the class XmlRpcClient.

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

The way I see it, there is no such thing as the "base object" in memory. For the given code snippet, there are only 3 custom object instances in memory. One of type B, C and D each; no A instance.

public class MemTest {
    public static void main(String[] args) {
        D d = new D();
        d.doIt();
    }
}

class A {}

class B {}

class C {}

class D extends A {    
    private C c;    
    private B b;    
    public D() {
        super();
        c = new C();
        b = new B();
    }    
    public void doIt() {
        System.out.println("HI");
    }
}

If you don't call `super.finalize()` inside the overridden `finalize` method of your subclass, the finalization of your subclass instance would complete and the space will be reclaimed *without* the finalize of the super class be invoked. This might be undesirable in cases where the `finalize` method of the super class is responsible for releasing scarce resources held by it (e.g. file handles).

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

AFAICT, the container has no way of knowing that it has to switch to HTTPS given that the forwarding happens within the code executing on the server. A resource is just a resource and by itself, it has no way of knowing whether it has to be served over a normal channel or a secure channel. Also, I think the configuration placed in the web.xml which relates to external requests made by the client and not internal forwards done.

Instead of doing a forward, try redirecting to that resource. It if still doesn't work, post your web.xml configuration along with the relevant piece of code you are using.

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

> But why will it decide to call the finalize() of D and C before A ?

AFAICT, as per the specification, the Java programming language makes no guarantee regarding the order in which finalize method is called on the "finalize eligible" objects.

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

Have you tried to understand the client examples posted on the official XML-RPC site? IMO, something like client.execute("System.listMethods", new ArrayList()) or client.execute("system.listMethods", new ArrayList()) should do the trick.

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

This is because the getObject() methods returns an Object and the Object class doesn't have the methods `getName` and `getAge`. You either need to cast the object returned by the `getObject` method to `Data` or "generify" your List class so that it accepts a type parameter just like the ArrayList class of JDK.

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

Post a "compilable" and "short" piece of code which demonstrates your problem.

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

Hi ~s.o.s~,

i still have "Cannot forward after response has been committed" error, even i have changed the code accordingly. Can help me take a look and advise me what is wrong with my code? =( Thanks.

~s.o.s~,i really thank for your help.

<%
            if (request.getAttribute("login") == null) {
                RequestDispatcher dispatcher =
                        request.getRequestDispatcher("/login.jsp");
                dispatcher.forward(request, response);
            }
            if (request.getAttribute("cash") == null) {
                RequestDispatcher dispatcher =
                        request.getRequestDispatcher("/login.jsp");
                dispatcher.forward(request, response);
            }
%>

You still haven't made those changes; like already mentioned if both 'login' and 'cash' are not present, you end up doing a `forward` twice. Replace the second `if` with an `if..else` and it should work out fine.

Also, try rewriting your code. Put the forwarding logic in a Servlet and have three conditional checks instead of the two present right now. Create three JSP's; no_cash.jsp, no_login.jsp and normal.jsp. Inside the servlet, write something along the lines of:

protected void doGet(HttpServletRequest req, HttpServletResponse res) {
  if(noLogin) {
     // forward to no_login.jsp
  } else if(noCash) {
    // forward to no_cash.jsp
  } else {
    // forward to normal.jsp
  }
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

When it comes to Derby, LAST has a special meaning. Instead of using 'LAST' as your column alias, use something like LNAME; it should work.

SELECT admin_lname as lname from admin
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

That query you posted doesn't have any use of 'AS'? Post the query which doesn't work for you.

> I will have to figure out how to replace 10.5.3.0 with the new version

Use the new 'bin' folder when starting the server and use the new client libraries when accessing the server using JDBC.

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

Yes, it's the same major version I'm using (10.5.1.1). Paste your table creation script with the "exact" query you are trying to execute; I might just give it a try. For the time being, download 10.5.1.1 instead of using 10.5.3.0 and try out your script on that version. If it works, then you'd have to take this to the Derby forums.

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

Have you tried this on some other *nix distribution like Fedora, Gentoo etc? If they manifest the same problem, it can be confirmed that this isn't a Ubuntu specific problem and more so a problem with the Java implementation for *nix. If the same issue doesn't show up, then you are better off asking the same question in Ubuntu official forums since this might be something "Ubuntu specific".

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

> but is there java code that is equivalent to this

Yes, look into the `forward` method of the `RequestDispatcher` interface. Read this.

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

Ensure that the required JARs are on the runtime classpath. You can download the required JNDI JARs from here.

Also, paste the entire stacktrace along with the tutorial you are referring to for others reference.

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

Decide a preference for your NULL checks; should the NULL check for `login` be performed before the NULL check for `cash` or vice versa. Use ELSE IF instead of just IF for the second conditional check.

When you forward, you are effectively saying that the forwarded page now has the responsibility of rendering the response. Forwarding to a page effectively "commits" /finalizes the response. Forwarding twice i.e. forwarding after the response has been committed results in an IllegalArgumentException as per the servlet specification.

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

Difficult to say anything without looking at the JSP in consideration. You can also try taking a look at the generated servlet for your JSP (process_jsp.java).

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

Which version of Derby DB are you using? I can make those statements work perfectly fine with Derby 10.5.

BTW, is the name of your table actually "table"?

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

`yourapp` is the name of your web application. You need to create a controller/servlet which accepts some input parameters and generates the images on fly which are then sent to the client. A simple example would be:

public class ImageServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse res)
		throws IOException, ServletException {
		String graphType = request.getParamter("type");
		// read other data like graph parameters
		BufferedImage img = generateImage(graphType);
		response.setContentType("img/png");
		OutputStream os = response.getOutputStream();
		// write data from BufferedImage to the servlet output stream
	}
}

In you deployment descriptor, map this Servlet against the path "/img". You can then use this servlet like:

<img src="/MyWebApplication/img?type=first" /><br />
<img src="/MyWebApplication/img?type=second" /><br />
<img src="/MyWebApplication/img?type=third" /><br />

Oh and when posting code the next time, use code tags. Failure to do so would result in your post being ignored by the regulars here; read forum rules for more details.

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

Your OS/CPU architecture limits the maximum heap size you can allocate for your JVM process. Read this.

The setting for heap size depends on the IDE which you are using but for eclipse, see this.

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

>> String l = Doc +"\\"+ file;

The problem is with this line. Windows uses backslash (\) as the file separator whereas *nix uses forward slash (/) as the file separator. The simplest solution here would be to *not* manually create file names/path but use a method which automatically gives you a list of File objects in a directory.

File dir = new File(baseDirPath);
for(File f : dir.listFiles()) {
  if(!f.delete()) {
    System.out.println("Failed to delete file: " + f);
  }
}
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Without seeing the code, it would be difficult to tell but are you updating your `demo` object so that it always fetches a new buffered image?

Also, this approach isn't a good one. You can at a given time write out only a single type of entity (to put it in simple terms); which is the reason why you set the content type of your writer/outputstream before writing out the response. A better solution here would be to have four IMG tags on your web page having different SRC values. For each SRC value, an appropriate byte stream would be retrieved for a given image and displayed to the browser.

Something like:

<html>
<head><title>Hi</title></head>
<body>
  <img src="/yourapp/img/img1" /><br/>
  <img src="/yourapp/img/img2" /><br/>
  <img src="/yourapp/img/img3" /><br/>
  <img src="/yourapp/img/img4" /><br/>
</body>
</html>
~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

If you need to change the contents of the file in-place, you'd need to:
- Use RandomAccessFile class
- Open the file in read/write mode
- Play around with file pointers (see javadocs for more details) and overwrite the existing content

I personally wouldn't recommend this approach due to the sheer amount of complexity involved in managing file pointers and keeping track of things.

Unless you are running under strict space/time constraints, a simpler approach would be to:
- Open the existing file using some Reader
- Create a new temporary file
- Read the text from the opened file and write the modified text to the newly opened file
- After the reading activity is complete, close the streams, delete the existing file and rename the temporary file so that it now becomes the original file
- Profit?! :)

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

You would need to specify the package qualified class name for both the dates.

java.util.Date utilDate = new java.util.Date();
java.sql.Date sqlDate = new java.sql.Date(2342334);

or something like:

import java.util.Date;

java.sql.Date sqlDate = new java.sql.Date(423423);
Date utilDate = new Date();  // util date
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

That isn't the responsibility of the toString() method of the Item class. If you need something like this, there are a couple of approaches you can adopt:
- Create a static utility method in a helper class which does the same (i.e. blank line after 10 items)
- Create a new abstraction; Store class which acts as a thin wrapper around the ArrayList and override its toString() method to do the same. The store arraylist in your main class will now be replaced by a variable of the Store class. Something like:

class Store {
  public List<Item> items = new ArrayList<Item>();

  public void addItem(Item item) {}

  public void removeItem(Item item) {}

  public String toString() {
    // loop over the items in the store/cart and add a blank
    // line every ten items
  }
}

I would personally prefer the second approach since it's much cleaner.

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

The error says that your Item class doesn't implement the Comparable<Item> interface; see my first post for the same.

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

Collections.sort() automatically takes cares of all the details as long as all the objects present in the collection (in your case a list) implement the Comparable interface (which you already have). Try passing your list to the Collections.sort() method and it *should* work out to be fine. If it doesn't, give specific details as to what output you got and what you were expecting.

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

You can read more about compareTo here and about the toString method here; ask again if you have any *specific* questions.

Regarding ID's, it's generally a good idea to represent ID's as string since it doesn't restrict the usage of other non-numeric characters when you actually need them. Anyways, if you still plan on using numbers, you can replace to string `id` variable in my post with your integer variable and there shouldn't be any problems as such.

Regarding eclipse; your code which you execute runs/executes in a separate JVM process which is different from the JVM process which runs eclipse. If you are using Eclipse, you need to alter the run configuration of your main class to modify the heap settings for that particular java program execution. Though I think that the problem really isn't the lack of heap memory but a sort implementation gone wrong; more specifically the part where you modify the collection as well as keep looping over it. Try using the standard sort implementation and the problem should most probably go away.

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

What's the size of your data set? Also, there are two types of OutOfMemoryError: out of heap space and out of perma-gen space. What does the error exactly say? Post the exact stacktrace of your application.

Also, there are better ways of sorting a collection containing your custom class. Make your class implement the Comparable interface and define the natural ordering for your class objects. Something like this:

import java.util.*;

public class Item implements Comparable<Item> {
  // TODO: Use getters and setters instead
  public String id;
  public String name;
  
  public Item(String id, String name) {
      this.id = id;
      this.name = name;
  }
  
  @Override
  public int compareTo(Item item) {
    int val = this.id.compareTo(item.id);
    if(val != 0) {
        return val;
    } else {
        return this.name.compareTo(item.name);
    }
  }
  
  @Override
  public String toString() {
      return "[id: " + this.id + ", name: " + this.name + "]";
  }
}

Item item1 = new Item("c", "comb");
Item item2 = new Item("a", "soap");
Item item3 = new Item("b", "shampoo");
List<Item> items = new ArrayList<Item>();
items.add(item1); items.add(item2); items.add(item3);
Collections.sort(items);
System.out.println(items);

Regarding the settings for adjusting memory usage, look into the JVM flags, specifically -Xmx for setting the maximum heap memory and -XX:MaxPermSize . You can then spawn your JVM process using something like:

java -Xmx256M -XX:MaxPermSize=64M your.pkg.YourMainClass
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Are you saying that you are not able to output the pipe character (|) using your keyboard? If yes, then try holding down SHIFT key and then press the key which has | and \ shown. If no, then post the code with which you are getting errors. Using the logical OR operator is as simple as:

boolean someStatus = someBoolean || otherBoolean;
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Does that even work for you? Which version of JSTL are you using?

Anyways, it seems that JSTL forbids literal comparison. Instead of:

<c:if test="${1 == 0}">SOMETHING HERE</c:if>

try out something like:

<c:set var="x" value="1" />
<c:if test="${x == 0}">SOMETHING HERE</c:if>
~s.o.s~ 2,560 Failure as a human Team Colleague Featured Poster

Instead of getting your hands busy with the libraries/API's provided by Java, you should concentrate on getting the language basics right. The stack trace in the previous post provides the exact reason as to *why* the code fails.

As far as your code is concerned, look into the DAO pattern for acessing databases. Centralize your connection related logic so that changing the database details doesn't involve sifting through thousands of Java files. Have you looked at this tutorial for at least a starting point?

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

It seems that the link has now been rightfully placed at below the last post. Much better.

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

Are you still facing the problem? Tried with a different browser? Though it might sound crazy, try logging out of the site, clearing your cookies and browser history, closing the browser and then try logging in again. I really can't come up with a logical explanation when it comes to the description you posted. :)