java

Using Servlets and JSP together resulting in unexpected looping.

I'm trying to use Servlets as a controller layer and JSPs as a view layer. Many of the examples/tutorials I've read suggest doing somehting like this: public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // add something for the JSP to work on request.setAttribute("key", "v...

Parsing a variable-length message

I am implementing the BitTorent protocol using Java via this spec. In the messages section all messages are fixed length except 2 of them; for one of them it's the only variable message after the handshake so I can check others and assume it's a piece message when no other messages met. But for the following message bitfield: <len=0001...

java, System.loadlibrary("someDLLFile") gets unstatisfied link error

Hello, I have written some JNI hooks into a C++ library and created some DLL files for my java server project. Lets say the DLL and jar files are in the same folder under "C:/server" I am accessing these DLL files using: System.loadLibrary("someDLLFile"); in the class that needs the C++ code. The problem I am running into is when I...

Convert a parameter entered as an integer to a string in JasperReports

I have a JRXML file that I use to generate a report built on a massive SQL query for an Oracle database. I have entered a parameter to the report that gets filled as an Integer. However, I would also like to reference this parameter as a String at a different point in the query. Is there a way I can convert the parameter from an Intege...

Server not receiving bytes written to a socket by Java app

I have the following Java socket client app, that sends same string to socket server: import java.net.*; import java.io.*; public class ServerClient { public static void main(String[] args) throws IOException { System.out.println("Starting a socket server client..."); Socket client = new Socket("XXX.X.XXX.XX", 12001); BufferedOutput...

A class that behaves like @Entity and @Embeddable

Hi, I have a one way @OneToMany relationship between a Team and Player class. I would like to save a Team object among your Players. Player's identifier IS COMPOUND by Team foreign key and list index as follows. I have a mapping like this one because i need to save Team and your Players ate the same time. @Entity public class Team { ...

Is my DAO strategy ok?

I'm using Hibernate. The question is at the bottom. The current strategy It's simple. First of all, I have a basic Dao<T>. public class Dao<T> { private Class<T> persistentClass; private Session session; public Dao(Class<T> persistentClass) { this.persistenClass = persistentClass; this.session = Hibernate...

Hibernate not creating entity tables if embedding components

I have made an application using Java/Hibernate/MySQL, but whenever I try running it, it complains that the table for one of my entity classes has not been created. After some trial and error, I have come to the conclusion that the problem is coming from the way I am mapping embedded components, but I do not know how I may fix it. Here...

How to use hibernate interceptors to populate extra fields in a join table?

I have a legacy object model that has content objects and a table designed to express relationships between content objects. The latter is called a content_content_connections table, and in addition to having the primary key of the from and to content, it also contains 3 other fields. A connection type field, and content type id fields...

Comparing a char to a code-point?

What is the "correct" way of comparing a code-point to a Java character? For example: int codepoint = String.codePointAt(0); char token = '\n'; I know I can probably do: if (codepoint==(int) token) { ... } but this code looks fragile. Is there a formal API method for comparing codepoints to chars, or converting the char up to a cod...

Please recommend a good Slime tutorial or screencast.

My adventures in Java have lead me to look into Clojure, which then lead me to (re)discover Emacs and that lead me to SLIME. I have a fairly decent handle on Emacs itself, and I have the emacs-starter-kit as well as clojure-mode/slime/swank as well as a few other unrelated modes and tweaks setup and running. But setting up a program an...

Java A4 printable document

Hello, I currently use an ActiveX control to print out an html document from a popup window without prompting the user. I've never liked this method and have finally got around to reconsidering the problem. I've decided to use a Java applet, and have already managed to get the promptless printing working. However, I've no experience w...

Experience migrating legacy Cobol/PL1 to Java

ORIGINAL Q: I'm wondering if anyone has had experience of migrating a large Cobol/PL1 codebase to Java? How automated was the process and how maintainable was the output? How did the move from transactional to OO work out? Any lessons learned along the way or resources/white papers that may be of benefit would be appreciated. ED...

best approach to extend a class funcionality in java?

for short, this could be paraphrased like "inheritance versus function library" for example, I'd like to add a method to the javax.servlet.http.HttpServletRequest that gives me the whole body, a getBody() method that would read the body thru the getReader method, just to put an example. In other languages, like ruby or javascript, you ...

Reliable/Safety-critical JAVA middleware - Best practices

What are the best practices for implementing reliable and safety-critical Java middleware? ...

Java app that uses a lot of memory. Use -Xmx?

I have a java app that uses about 15G on a machine with 16G. I don't know if I should set the max heap size. If I set will the jvm eat all the ram up to the limit and then start garbage collecting and stop everything while it churns through 15G or heap objects? If I don't will the jvm hurt performance by not using all of the availab...

How to keep Hibernate mapping use under control as requirements grow

I've worked on a number of Java web apps where persistence is via Hibernate, and we start off with some central class (e.g. an insurance application) without any time being spent considering how to break things up into manageable chunks. Over time as features are added we add more mappings (rates, clients, addresses, etc.) and then amoun...

How can I map a "root" Servlet so that other scripts are still runnable?

I'm trying to build a Servlet that calls a JSP page similar to the following: public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException { req.getRequestDispatcher("/WEB-INF/main.jsp").forward(req, resp); } I need this Servlet to respond to the domain's root (eg: http://example.com/) so...

How do you add a dependency to a JBoss EJB with a generated WebService?

I'm trying to deploy an EJB in JBoss that uses the @WebService annotation. However, the EJB has a dependency on an EJB in another ear. By adding the @Depends annotation, the EJB start is delayed until after the ear is loaded, but it appears the WebService generator is still trying to start up the generated WAR as soon as it sees the anno...

In Java, where in the package/source hierarchy should resources be placed?

Say I have developed a game, and placed it in the package structure: com.dxmio.games.breakout Where then is the 'best practice' place to put resources like audio and images that the game uses? ...