java

Modify HttpServletRequest before any HandlerMapping?

The problem I am trying to solve is that I want to check all incoming GET urls against a database. If the the url exist in the database it shall be passed to a certein controller. I'm using Spring 3.0. First I tried to make an interceptor and add that to DefaultAnnotationsHandlerMapping. Turns out i couldn't modify the url in preHandle(...

java+swing+mvc: how to make a model that interfaces w/ multiple controls?

I have this Swing app I'm working on that has a pair of JSliders and JTextFields that both display & control the value of two numbers. Right now I kind of hacked things together to make it work, intercepting change events and updating the display. However I'm thinking a better way would be to make a model that has the two numbers and som...

How can i use JSTL variable in scriptlet?

I have to access the JSTL variable which is calculated inside the iterator. Excerpt of code: <c:forEach var="resultBean" items="${resultList}" varStatus="status"> card: ${resultBean.cardNum} </c:forEach> i would like to access ${resultBean.cardNum} in the scriptlet code. what i am doing right now is: <c:forEach var="resultBe...

Hibernate Criteria / Query on object properties

I have a class AppUser; class AppUser { private String firstName; private String lastName; //-- getters and setters } I also have another class Student; class Student { private AppUser appUser; private Date dateOfBirth; //-- getters and setters } How would i search for Student John Doe, firstName John, lastName Do...

printing out prime numbers from array

I'd like to print out all prime numbers from an array with method. I can do it with one int but don't know how to return certain numbers from array. Thanks for help! public static boolean isPrime(int [] tab) { boolean prime = true; for (int i = 3; i <= Math.sqrt(tab[i]); i += 2) if (tab[i] % i == 0) { ...

Casting performance in Java

I've a Servlet filter which performs the following type cast: HttpServletRequest httpRequest = (HttpServletRequest) req; At present my filter is responsible for two tasks that would be better separated into two filters. If I'd split the logic into two filters I'd need two casts. What is the performance impact of such a cast? Is it wo...

Http Streams with Java

Hi, I'm looking for the best way to stream live data over the http protocol with java. I'm currently using HttpURLConnection to receive json feeds, I would like to know if it can be used to stream feeds too. ...

If found, return value one tab over [java]

I've successfully created an item scanner for my game. Here is my code: import java.io.*; import java.util.*; public class ItemScanner { public static void main(String args[]) { System.out.print("Enter item to find: "); Scanner sc = new Scanner(System.in); find(sc.nextLine()); } public static v...

Why StringBuffer and StringBuilder append methods discard the value returned by the super call

This is a question out of curiousity. Today I took a look at the implementations of StringBuilder and StringBuffer. Here's the append() method: public StringBuilder append(String str) { super.append(str); return this; } AbstractStringBuilder.append(str) also returns this. Are there any benefits of discarding the return value (...

What's wrong with Java Date & Time API?

Very often I come across negative feedback on Java Date and other date-time-related classes. Being a .NET developer, I cannot fully (without having used them) understand, what's actually wrong with them. Can anybody shed some light on this? ...

Use of Hashmap for multiple vales of keys and why?

I am stuck here: my input file: 123 456 789 872 727 282 123 838 831 818 833 939 Now, I need to save data in a hashmap, 2d array or any best possible alternative like this: key value 123 -> 456, 789, 838, 831 872 -> 727, 282 818 -> 833, 939 What is the best possible way (simple and optimized) to achieve this and using what? I a...

In Java or .NET, how would you create a server that listens to a specific port?

In Java or .NET, how would you create a server that listens to a specific port? (Just a dummy server, I just want to get the high level idea.) ...

How can I specify dependency in JPA without links from owner entity?

The goal is to remove all Dependent when their Owner is deleted. I have the following classes: @Entity class Dependent { @ManyToOne(cascade = CascadeType.PERSIST, fetch = FetchType.LAZY, optional = false) @Column(name = "OWNER") private Owner _owner; } @Entity class Owner { ... } In the current implementation Dependen...

WebBrowser1 problem with external web app.

the external Application works good in IE so i know the problem is inside My App. The external web app is java applet and java script based, and the problem im experiensing is when the java applet tryes to run a java script. The Applet opens a seconday window with a java script and tryes to do some operations but then i just stops. And ...

Best Way to place temporary Data for an Webapp

My newest project is able to generate documents with information from a database. So I copy the document template on demand to an temporary folder for a user and modify it. I do this because every template must be available during modification. Afterwards the user is awarded with his document via a download link from my webapp. My que...

android: set up simplest opengl es app.

hello, i am looking for some sample code or tutorial that sets up the most basic opengl es application. for example, just do glClear() in the renderloop. i have already been searching the web but all i found was either out of date or too much and too complicated. thanks! ...

Entire jar is read for every getResourceAsStream

Hi I am profiling a java applet startup time. I have noticed that a huge jar of size 5MB is fully read every time a resource from the jar is requested. E.g. images log configuration files, I18N files etc.... Sould it behave that way? Is it possible just to jump to the correct point ? Is it possible to read the file only once? If I will...

Defining muliple hash functions for the same object

I have several Sets that store the objects of the same class, but I want to specify a different identity function for each of them (i.e. say, in one set A==B if A.x==B.x, while in another A==B if A.y==B.y). Currently I use TreeSets with different Comparators defined for each. I am wondering how the same thing can be done if I want to sw...

Display only found results [java]

A follow up to my Item Scanner, a java tool that scans through a directory of *.txt files. Thank you all for the help! However now I have a different problem. When I get the results it reads strings I do not want it to read. How can I block out these strings I do not want it reading? This is an example what I mean: Enter item to fin...

Can a java application manage triggers and UDFs in Derby database ?

Can we manage UDFs, and triggers in Derby database from our own Java Application ? By managing I mean : checking if it exists; adding; removing. ...