java1.4

get jsp response as a string inside servlet

点点圈 提交于 2019-11-30 16:03:28
问题 Is there a way to get response from a jsp file as a String inside servlet. Something like protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String section1 = getResponseFromJSP(); // do something else ... sendMailToUser(section1); } I'm using Servlet API 2.4 and java 1.4 回答1: A better solution might be to use another template engine like freemarker or velocity, which are independent of the servlet api and more suited for

What is the Java 1.4.2 equivalent of Pattern.quote()

坚强是说给别人听的谎言 提交于 2019-11-28 13:33:39
What would be a Java 1.4.2 equivalent of Pattern.quote? I was using Pattern.quote() on a URI but now need to make it 1.4.2 compatible. Well the source code of Pattern.quote is available and looks like this: public static String quote(String s) { int slashEIndex = s.indexOf("\\E"); if (slashEIndex == -1) return "\\Q" + s + "\\E"; StringBuilder sb = new StringBuilder(s.length() * 2); sb.append("\\Q"); slashEIndex = 0; int current = 0; while ((slashEIndex = s.indexOf("\\E", current)) != -1) { sb.append(s.substring(current, slashEIndex)); current = slashEIndex + 2; sb.append("\\E\\\\E\\Q"); } sb

Backport Java 5/6 features to Java 1.4?

若如初见. 提交于 2019-11-28 08:42:36
We are stuck with Java2SE v1.4 till the end of 2010. That's really nasty, but we can't help it. What options do we have to use some of the new features already now? I can think of several ways like changing the bytecode, e.g. using Retrotranslator or Retroweaver . backport of libraries, e.g. Concurrent Backport , but this does not help for generics. emulation of Java 5 features, e.g. checked Collections, Varargs with helper methods, etc. changing source code by precompilation, stripping all 1.5 stuff before final compilation, e.g. using Declawer can do this. I am most interested in very

Alternative to enum in Java 1.4

余生颓废 提交于 2019-11-28 07:38:59
Since Java 1.4 doesn't have enums I'm am doing something like this: public class SomeClass { public static int SOME_VALUE_1 = 0; public static int SOME_VALUE_2 = 1; public static int SOME_VALUE_3 = 2; public void receiveSomeValue(int someValue) { // do something } } The caller of receiveSomeValue should pass one those 3 values but he can pass any other int. If it were an enum the caller could only pass one valid value. Should receiveSomeValue throw an InvalidValueException? What are good alternatives to Java 5 enums? Best to use in pre 1.5 is the Typesafe Enum Pattern best described in the

How to debug Java OutOfMemory exceptions?

佐手、 提交于 2019-11-28 06:33:43
What is the best way to debug java.lang.OutOfMemoryError exceptions? When this happens to our application, our app server (Weblogic) generates a heap dump file. Should we use the heap dump file? Should we generate a Java thread dump? What exactly is the difference? Update: What is the best way to generate thread dumps? Is kill -3 (our app runs on Solaris) the best way to kill the app and generate a thread dump? Is there a way to generate the thread dump but not kill the app? Analyzing and fixing out-of-memory errors in Java is very simple. In Java the objects that occupy memory are all linked

How do you set a timeout on BufferedReader and PrintWriter in Java 1.4?

橙三吉。 提交于 2019-11-28 00:45:45
How does one set a timeout on a BufferedReader and a PrintWriter created using a socket connection? Here is the code I have for the server right now, which works until either the server or the client crashes: while(isReceiving){ str = null; BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream())); PrintWriter pw = new PrintWriter(socket.getOutputStream(), true); while ((str = br.readLine()) != null){ System.out.println("Processing command " + str); pw.println(client.message(str)); } } Outside the scope of this code I have imposed a socket timeout of 1000ms, which

Alternative to enum in Java 1.4

安稳与你 提交于 2019-11-27 01:54:36
问题 Since Java 1.4 doesn't have enums I'm am doing something like this: public class SomeClass { public static int SOME_VALUE_1 = 0; public static int SOME_VALUE_2 = 1; public static int SOME_VALUE_3 = 2; public void receiveSomeValue(int someValue) { // do something } } The caller of receiveSomeValue should pass one those 3 values but he can pass any other int. If it were an enum the caller could only pass one valid value. Should receiveSomeValue throw an InvalidValueException? What are good

How to debug Java OutOfMemory exceptions?

拟墨画扇 提交于 2019-11-27 01:10:30
问题 What is the best way to debug java.lang.OutOfMemoryError exceptions? When this happens to our application, our app server (Weblogic) generates a heap dump file. Should we use the heap dump file? Should we generate a Java thread dump? What exactly is the difference? Update: What is the best way to generate thread dumps? Is kill -3 (our app runs on Solaris) the best way to kill the app and generate a thread dump? Is there a way to generate the thread dump but not kill the app? 回答1: Analyzing