5/28/08


Remote debugging

JBoss:

set JAVA_OP TS=-Xdebug -Xnoagent -Djava.compiler=NONE -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 %JAVA_OPTS%

WebLogic:

@REM insert this line
set debugFlag=true
@REM before:
if "%debugFlag%"=="true" (
set JAVA_DEBUG=-Xdebug -Xnoagent -Xrunjdwp:transport=dt_socket,address=%DEBUG_PORT%,server=y,suspend=n -Djava.compiler=NONE
set JAVA_OPTIONS=%JAVA_OPTIONS% %enableHotswapFlag% -ea -da:com.bea... -da:javelin... -da:weblogic... -ea:com.bea.wli... -ea:com.bea.broker... -ea:com.bea.sbconsole...
) else (
set JAVA_OPTIONS=%JAVA_OPTIONS% %enableHotswapFlag% -da
)

Dynamo 6.3:

startDynamo.bat drp1 -m sfx -debug -debugPort 8787

Tomcat:

Set environment variables JPDA_ADDRESS=8000 and JPDA_TRANSPORT=dt_socket and then start tomcat using catalina jpda start

5/26/08


Java Binary / XML Serialization

XMLEncoder under Java 5 did not cope with serialization task:

import java.beans.XMLEncoder;
import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import com.thoughtworks.xstream.XStream;

public class Main {

public static void main(String[] args) throws FileNotFoundException {
HashMap hm = new HashMap();
hm.put("string1", new ForSer("string1", 10));
hm.put("string2", new ForSer("string2", 101));
hm.put("string3", new ForSer("string3", 1011));
hm.put("string4", new ForSer("string4", 10111));
// FileOutputStream fos = new FileOutputStream("d:/foo.xml");
// XMLEncoder xenc = new XMLEncoder(fos);
// xenc.writeObject(hm);
// xenc.flush();
// xenc.close();
XStream xstream = new XStream();
System.out.println(xstream.toXML(hm));

//Binary:
ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos) ;
oos.writeObject(new ForSer("string", 111));
byte[] bar = baos.toByteArray();
System.out.println(new String(bar));
}
static class ForSer implements Serializable {
private static final long serialVersionUID = 1L;
private String str;
private int count;

public String getStr() {
return str;
}
public void setStr(String str) {
this.str = str;
}
public int getCount() {
return count;
}
public void setCount(int count) {
this.count = count;
}
public ForSer(String str, int count) {
super();
this.str = str;
this.count = count;
}
}
}

5/5/08


JSP Mix

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
< title> Insert title here </title >
<link href="css/index.css" rel="stylesheet" type="text/css">
</head>
<body>
Hello <br /> My darling.
<%-- SCRIPTING ELEMENTS START --%>
<% //scriplet
out.println("-= ## =-");
JspWriter jw = out;
response.getWriter().write("*-*-*-*-*");
%>
<%= //expression
new Integer(50).toString()
%>
<%! //declaration
/*
public void init(){
}
public void destroy(){
}*/
public void jspInit(){
Servlet s = (Servlet)this;
JspPage jp =(JspPage)this;
HttpJspPage hjp = (HttpJspPage)this;
System.out.println("jspInit()");
}
public void jspDestroy(){
System.out.println("jspDestroy()");
}
%>
<%-- SCRIPTING ELEMENTS END --%>
<!-- HTML Comment -- >
<%-- JSP Comment --% >
<jsp:useBean id="myBean" scope="application" class="java.lang.String"></jsp:useBean>

</body>
</html>

EL (Expression Language) was introduces in JSP 2.0!

Some interesting jsp code to generate colored effects:
<% for(int i=0; i< 4095; i++){%>
<div style="
background-color: #<%=Integer.toHexString(0x1000|i).substring(1)%>;
height:1px;"></div>
<%}%>

Form with drop-down list that save its state:

<form action="index.jsp" method="get">
<select size="1" <%-- multiple="multiple" --%> name="join">
<option <%= request.getParameter("join") == null ? "selected" : "" %> ></option>
<option <%= request.getParameter("join") != null && request.getParameter("join").equals("right") ? "selected" : "" %> value="right">right</option>
<option <%= request.getParameter("join") != null && request.getParameter("join").equals("left") ? "selected" : "" %> value="left">left</option>
<option <%= request.getParameter("join") != null && request.getParameter("join").equals("full") ? "selected" : "" %> value="full">full</option>
</select>
<input type="submit" value="sub">
</form>