java

Which Java templating system should I use to generate emails?

I have a website that uses JSP as its view technology (and Spring MVC underneath). Unfortunately, JSP is just a pain to use for anything that doesn't involve an HTTP session. I would like to be able to occasionally send my users some email, and I want to use something JSP-like to render the email's contents. Technologies I'm aware of ...

Persistence.xml and OSGi (Equinox)

I am currently testing out using OSGi. I am running this through Eclipse. I want to have my DAO layer as part of an OSGi solution, but my first stumbling block is this error: Jun 29, 2009 6:12:37 PM org.hibernate.cfg.annotations.Version <clinit> INFO: Hibernate Annotations 3.3.0.GA Jun 29, 2009 6:12:37 PM org.hibernate.ejb.Version <cl...

Java: If vs. Switch

I have a piece of code with a) which I replaced with b) purely for legibility ... a) if ( WORD[ INDEX ] == 'A' ) branch = BRANCH.A; /* B through to Y */ if ( WORD[ INDEX ] == 'Z' ) branch = BRANCH.Z; b) switch ( WORD[ INDEX ] ) { case 'A' : branch = BRANCH.A; break; /* B through to Y */ case 'Z' : branch = BRANCH.Z; brea...

JWS JNLP no Desktop Icon on Mac

I seem to be having a problem getting the icon for a Java Web Start program to appear on the Mac desktop, or under "Applications". The icon's and menu's are created and work properly under windows XP and Vista, is there something different that must be done for Macs? On the Mac there aren't output any errors, it prompts me with the ques...

SHA-1 Hashes Mixed with Strings

I have to parse something like the following "some text <40 byte hash>" can i read this whole thing in to a string without corrupting 40 byte hash part? The thing is hash is not going to be there so i don't want to process it while reading. EDIT: I forgot to mention that the 40 byte hash is 2x20 byte hashes no encoding raw bytes. ...

Get Windows Service Pack Version from Java Applet?

Hello I am writing a Java Applet. When run on Windows, I need to be able to get the clients OS version, e.g. Windows XP SP3 or Windows 2000 SP4. I can currently use the following: String os_name = System.getProperty( "os.name" ); String os_version = System.getProperty( "os.version" ); System.out.println( "Running on " + os_name + ...

Writing a function: short GetBits(short data, int p, int n)

I am writing a function short getBits(short data, int p, int n) I have tried: public static short getBits(short data, int p, int n) { short bitmask = (short) ((~0 << (16 -n)) >>> p); short returnVal = (short) ((bitmask & data) >>> (16 - n)); return returnVal; } This works for getBits( (short) 0x7000, 0, 4) but if I were to replac...

LDAP: How to search for a given uid across multiple organization units?

First off, let me start by saying that I am totally new to working with LDAP. I am working on an application that shares an LDAP server with a few legacy applications. All of the user accounts in the legacy application are organized into Organizational Units by IDs. Each entry has a uid that is the users email address. I can find ...

Java Regular Expression, match everything but

Hi all, I would like to match everything but *.xhtml. I have a servlet listening to *.xhtml and I want another servlet to catch everything else. If I map the Faces Servlet to everything (*), it bombs out when handling icons, stylesheets, and everything that is not a faces request. This is what I've been trying unsuccessfully. Patter...

What exactly is Spring for?

I hear a lot about spring, people are saying all over the web that Spring is good framework for web development. But what exactly is it for? How can I use it for my Web-Java application any examples. ...

problem when exporting to excel with JSF

Hello, I'm using JSF/ICEFaces. The page is ICEFaces however I'm using the JSF datatable because ICEFaces had slow performance for some reason. Anyway, unlike the ICEFaces datatable, the JSF table doesn't come with export to excel so I'm writing my own. I decided to use Apache POI as below. The code executes well but I don't see pop up t...

IP Address not obtained in java

This code used to return my local ip address as 192.xxx.x.xxx but now it is returning 127.0.0.1 . Please help me why the same code is returning different value. Is there something that I need to watch at linux OS. import java.util.*; import java.lang.*; import java.net.*; public class GetOwnIP { public static void main(String args[])...

is startsWith faster than indexOf

I am writing some java code where I branch off based on whether a string starts with certain characters while looping through a dataset and my dataset is expected to be large. I was wondering whether startsWith is faster than indexOf. I did experiment with 2000 records and did find any difference. ...

Create java application jar file in eclipse

Hi, I have created a java application in eclipse, wich needs comm.jar and jexcel.jar and .property files so i have added to libray. I want to make a jar file out of my java appliction, including the external jar files added to the appliction. How can I do it? To run serialport programs I have copied win32.dll into java_home/bin and com...

useBean tag

Hi, I'm really confused in the following two lines of Head First servlets & JSP book of page no. 349: The is a way of declaring and initializing the actual bean object you're using in . 2.Declare and intializea bean attribute with <jsp:useBean> <jsp:useBean id="person"class="foo.Person" scope="request"/> In the first line, why...

Fastest way to write huge data in text file Java

I have to write huge data in text[csv] file. I used BufferedWriter to write the data and it took around 40 secs to write 174 mb of data. Is this the fastest speed java can offer? bufferedWriter = new BufferedWriter ( new FileWriter ( "fileName.csv" ) ); Note: These 40 secs include the time of iterating and fetching the records from re...

Updating a java map entry

Hi, I'm facing a problem that seems to have no straighforward solution. I'm using java.util.Map, and I want to update the value in a Key-Value pair. Right now, I'm doing it lik this: private Map<String,int> table = new HashMap<String,int>(); public void update(String key, int val) { if( !table.containsKey(key) ) return; Entry...

How to send a file over a network using socket channel in java

I want to write a socket channel program using which I can send a file from the client program to the server program. I want to create this program using Java. Is there any other on-line help is available So how to overcome this problem. Thanks Sunil Kumar Sahoo ...

C++ library with a Java-like API

Hello. Hoping that anybody here knows about a good one: I'm looking for a (free to use) C++ library with a class hierarchy and methods resembling the Java API, with at least the I/O & networking part if it, specifically HTTP handling. I work mainly with C & Java, but for this particular project C++ is recommended, so I thought of adopt...

Property file in java

Hi, I want read property file in my java class. for this i have written: try { Properties property = new Properties(); property .load(new FileInputStream("abc.properties")); String string = property.getProperty("userName"); } catch (Exception e) { e.printStackTrace(); } ...