java

How best to sanitize input in Java webapp

We use jsp, servlets, beans with mysql database. We don't want to restrict the characters entered by users on form fields. So how do I sanitize the input and how to make sure the output is not changed for malicious activities. Is there way while sending the output I could check if extra code has been sent. Like suppose there is search in...

Why am I getting this UnsatisfiedLinkError with native code?

I have a library called HelloWorld.so and a program HelloWorld.java with this content: class HelloWorld { private native void print(); public static void main(String[] args) { new HelloWorld().print(); } static { System.loadLibrary("HelloWorld"); } } Now when I try to run HelloWorld.java I g...

Different views with Spring's SimpleFormController

I'm using Spring's SimpleFormController for form processing. In my case, the edit view (JSP) can vary depending on what's being edited. SimpleFormController's formView is a field (class variable) which means that it's shared by all threads that use the instance of it. Thus it's not safe (nor appropriate) to set the formView (via setFormV...

Why am I getting an error when I try to run my socket program in Java?

I'm using jcreatorLE and JDK 1.6 to run my program. I don't know why I get an error when I try to run. Could somebody explain the reason to me? This is the code for the Server: import java.io.*; import java.net.*; class ServidorTCP { // variable to wait for connections private static ServerSocket servidor = null; // Variable...

Java Collections API Bug?

I've stumbled upon a bug in the Java Collections API, in Collections.java. Here’s the code verbatim from the JDK’s source. Just so you know, the JavaDoc version tag reads "1.106, 04/21/06". The method is located in line 638. public static <T extends Object & Comparable<? super T>> T max(Collection<? extends T> coll) { Iterator<? ex...

Do singleton exceptions work?

A collegue of mine at work gave a presentation on static factory methods (right out of Effective Java), and then gave an example of its use for obtaining static / singleton exceptions. This set off a red flag for me. Aren't exceptions stateful? Aren't they populated by the JVM for stack trace info? What savings do you really get wi...

How to display all elements in an arraylist?

Say I have a car class with attributes make and registration, and i create an ArrayList to store them. How do I display all the elements in the ArrayList? I have this code right now: public Car getAll() { for(int i = 0; i < cars.size(); i++) //cars name of arraylist { Car car = cars.get(i); { retu...

How to disable Java security manager?

Is there any way to completely disable Java security manager? I'm experimenting with source code of db4o. It uses reflection to persist objects and it seems that security manager doesn't allow reflection to read and write private or protected fields. My code: public static void main(String[] args) throws IOException { System.out....

where to put .properties files in an Eclipse project?

I have a very simple properties file test I am trying to get working: (the following is TestProperties.java) package com.example.test; import java.util.ResourceBundle; public class TestProperties { public static void main(String[] args) { ResourceBundle myResources = ResourceBundle.getBundle("TestProperties"); ...

Java alternative to Windows Workflow Foundation

What Java alternatives are there to Windows Workflow Foundation? I am looking for something that provides at least the same features that WWF does, and has the same flexibility and relative ease of use. I would very much prefer a free solution. ...

How Do I make dynamic-attributes Work in JSP Tag Files?

So according to my JSP reference book, as well as every other reference I can find on the web, I'm supposed to be able to do something like: <%@ tag dynamic-attributes="dynamicAttributesVar" %> and then when someone uses an attribute that I didn't define in an attribute directive, I should be able to access that attribute from the "dy...

.net alternatives for available java programs

I have seen some question asking java alternative for something which is available in .net Example : http://stackoverflow.com/questions/762499/java-alternative-to-windows-workflow-foundation I am interested to know if there is anything else that is available in java and we have to look for an alternative in .net. I am a MS based techn...

How do I use TestNG with Apache Ivy?

I tried to use TestNG with Apache Ivy, but was unsuccessful. Here is my ivy.xml: <ivy-module version="2.0"> <info organisation="me" module="myproject"/> <dependencies> <dependency org="org.testng" name="testng" rev="5.8" /> </dependencies> </ivy-module> This fails to actually download a TestNG jarfile. It seems to...

OSGi Service wrapping a jar

Hello all, I am trying to create an OSGi service that wraps another jar. I added the jar to the project, the classpath and the binary build. I registered the service in the Activator but when the consuming bundle calls the service I get a java.lang.NoClassDefFoundError on the wrapper jar. Does anyone have any idea what I am doing wrong ...

Server Design and Implementation

I've work in embedded systems and systems programming for hardware interfaces to date. For fun and personal knowledge, recently I've been trying to learn more about server programming after getting my hands wet with Erlang. I've been going back and thinking about servers from a C++/Java prospective, and now I wonder how scalable syste...

MidiUnavailableException in Java?

Hi, I'm having some trouble playing MIDI files in Java. What I get is a MidiUnavailableException (MIDI OUT transmitter not available) when I try to play it. My code is standard: try { midiseq = MidiSystem.getSequencer(); midiseq.open(); midiseq.setSequence(MidiSystem.getSequence(sound1)); midiseq.setLoopCount(Sequencer.L...

What Java framework would you use with Google App Engine?

It's been a while since I've done any website with with Java, and am wondering what framework options are out there for Google App Engine. What framework would you suggest for someone who has no real preference? I like Ruby On Rails, and am getting into Django, and like that as well. Professionally I'm a ASP.NET developer so I have th...

How do you configure Apache Ivy to remove orphan artifacts?

Let's say I have an ivy.xml that contains the following: <dependency org="checkstyle" name="checkstyle" rev="4.3" /> And then I want to upgrade to Checkstyle 4.4, so I change my ivy.xml to contain: <dependency org="checkstyle" name="checkstyle" rev="4.4" /> After a retrieve with the first configuration, I have the file checksty...

Java: Dependency Injection on foreign-constructed objects?

Hello! I'm a huge fan of D.I. I'm currently developing a not-so-small project which uses D.I. everywhere (classic and beautiful D.I. by hand). From my point of view there are following advantages: It's intuitive when you got used to it, doesn't affect readability in negative way (in fact, it gets even better), but the most importan...

[JAVA] how to send multiple data in 1 single UDP datagram?

hi all, i'm working on a network programming assignment about writing a simple IM system (pretty much like the simplest version of windows messenger). the spec specifies that i must send over 4 fields of data in a single datagram packet, those are: To From Type Message where type refers to message type, implemented as a user defined enu...