Showing posts with label Java. Show all posts
Showing posts with label Java. Show all posts

Thursday, September 6, 2012

Excel export With "save as Excel" Prompt from JSP



<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%      
response.setContentType("application/vnd.ms-excel");
response.setHeader("Content-Disposition", "attachment;filename=\"report.xls\"");

%>
<sql:query var="result" dataSource="jdbcJNDI">
        
        select * FROM 
        X
        WHERE
        X.y = ? and X.z = ?
        
       
        
        <sql:param  value="${param.from}"/>
        <sql:param  value="${param.to}"/>
    </sql:query>
    <table border="1">
        <!-- column headers -->
        <tr>
        <c:forEach var="columnName" items="${result.columnNames}">
            <th><c:out value="${columnName}"/></th>
        </c:forEach>
    </tr>
    <!-- column data -->
    <c:forEach var="row" items="${result.rowsByIndex}">
        <tr>
        <c:forEach var="column" items="${row}">
            <td><c:out value="${column}"/></td>
        </c:forEach>
        </tr>
    </c:forEach>
</table>

Share Article : Excel export With "save as Excel" Prompt from JSP
Share/Save/Bookmark

CSV, how to avoid crappy auto-format in Excel



Output date as a String as following

"=\""+$F{dd/mm/yyyy date}+ "\""   (in jasper)


 "=""01/01/2012"""  (finally following will be generated)

Share Article : CSV, how to avoid crappy auto-format in Excel
Share/Save/Bookmark

Monday, January 16, 2012

Remove Blank Lines in Java Code with NetBeans (regex)


Open the 'Find and Replace' window. Type \n\s*(\n) in the Find What field and $1 in the Replace With field. Check the Regular Expressions box and click Replace All.
Boom! All blank lines are removed now.

Share Article : Remove Blank Lines in Java Code with NetBeans (regex)
Share/Save/Bookmark

Monday, August 24, 2009

Java EE 6,Free Webinar (register before Aug 26)


Topics.......

  • Java EE evolution
  • Java EE 6 features overview
  • GlassFish v3 features
  • Getting started with Java EE 6


DATE : Wednesday, August 26, 2009
TIME : 10.30 PM (LOCAL TIME)
REGISTER HERE
(then u'll get a participation link by email)

Share Article : Java EE 6,Free Webinar (register before Aug 26)
Share/Save/Bookmark

Tuesday, August 11, 2009

Free 90-Day GlassFish Training(Web Services,App serv and more)



Learn the fundamentals of Sun GlassFish Enterprise Server and Web
Services with the following FREE 90-day Training Trial,
which includes:

• GlassFish Application Server: Introduction
• Designing Java Web Services
• Adding Quality of Service and .NET Interoperability to Web Services
• Creating Reliable and Secure Interoperable Web Services
• Creating Transactional Web Services
• Working With the Web Services Policy


Step 1: Register -- Create a new one-time use account that will be valid for 90 days.

Step 2: Enter the following for Company Name: Glassfish4Free and for Company ID: Glassfish4Free


Share Article : Free 90-Day GlassFish Training(Web Services,App serv and more)
Share/Save/Bookmark

Monday, July 13, 2009

J2ME Bluetooth connection steps


Following are the connection setup steps for J2ME Bluetooth.
(example shows Connecting to Server mode connection already
created with btspp)
  1. Inititate Search for devices.
  2. Method "deviceDiscovered" called by flatform for each device.
  3. Method "inquiryCompleted" called by flatform when device search completes.
  4. Then do a service search for selected device.
  5. Method "servicesDiscovered" called by flatform for each service.
  6. Method "serviceSearchCompleted" called by platform when service search completes.
  7. (there open a StreamConnection to chosen service URL)



//step 1
public void SearchAvailDevices() {
try {
//First get the local device and obtain the discovery agent.
m_LclDevice = LocalDevice.getLocalDevice();

m_DscrAgent = m_LclDevice.getDiscoveryAgent();

m_DscrAgent.startInquiry(DiscoveryAgent.GIAC, this);
} catch (BluetoothStateException ex) {
vobt.addLog("Problem in searching the blue tooth devices : " + ex.getMessage());
System.out.println("Problem in searching the blue tooth devices");
ex.printStackTrace();
}

}
//step 2 -- PLATFORM CALL
//Called when device is found during inquiry
public void deviceDiscovered(RemoteDevice btDevice, DeviceClass cod) {

try {
// Get Device Info
System.out.println("Device Discovered");
System.out.println("Major Device Class: " + cod.getMajorDeviceClass() + " Minor Device Class: " + cod.getMinorDeviceClass());
System.out.println("Bluetooth Address: " + btDevice.getBluetoothAddress());
System.out.println("Bluetooth Friendly Name: " + btDevice.getFriendlyName(true));
vobt.addLog("**Device Discovered**");
vobt.addLog("#Major Device Class: " + cod.getMajorDeviceClass() + " Minor Device Class: " + cod.getMinorDeviceClass());
vobt.addLog("#Bluetooth Address: " + btDevice.getBluetoothAddress());

//put remote devices in Array
remoteDevicesArray[deviceCount] = btDevice;
deviceClassesArray [deviceCount] = cod;
deviceCount++;
} catch (Exception e) {
System.out.println("Device Discovered Error: " + e);
vobt.addLog("deviceDiscovered : " + e);
}
//step 3--PLATFORM CALL
//when device search completes
public void inquiryCompleted(int discType) { }
//step 4
//Search for srvices in Given device as following
public void serviceSearch(int selectedIndex)
{
try {
UUID[] uuidSet = new UUID[1];
uuidSet[0] = RFCOMM_UUID; // UUID USED TO INITIATE SERVER
int searchID = m_DscrAgent.searchServices(null, uuidSet, remoteDevicesArray[selectedIndex], this);
} catch (BluetoothStateException ex) {
ex.printStackTrace();
vobt.addLog("deviceDiscovered : " + ex);
}
}
// step 5 -- PLATFORM CALL
//when service found during service search (for each time new service found)
public void servicesDiscovered(int transID, ServiceRecord[] records) {

for (int i = 0; i < records.length; i++) {
m_strUrl = records[i].getConnectionURL(ServiceRecord.AUTHENTICATE_ENCRYPT, false);

System.out.println(m_strUrl);
if (m_strUrl.startsWith("btspp")) //search for URLS with btspp
{
m_bServerFound = true;
m_bInitClient = true;
break;
}

}
}


// step6 -- PLATFORM CALL
// when service search complete for given device
public void serviceSearchCompleted(int transID, int respCode) {
try { // open stream connection with needed URL
StrmConn = (StreamConnection) Connector.open(m_strUrl);
}
catch()
{}
}




Share Article : J2ME Bluetooth connection steps
Share/Save/Bookmark

Sunday, July 12, 2009

Hibernate querying and iteration using JSTL


1.If a query return a single raw with data from mulitple tables
(unique result with mulitple objects in-hibernate),
it returns array of Entity Objects.
A[0]
A[n]
....

2.If a query return multiple raws with data from mulitple tabels
it return List of Array objects.
L[0] ---
|+--- A[0]...A[m]
L[n] ---
|+--- A[0]...A[m]
.....

Code for situation 1

SQLQuery query = session.createSQLQuery(sql);
query.addEntity("person", Person.class);
query.addEntity("specializations", Entity.Specializations.class);

Object obj = query.uniqueResult();
// obj is an array
//A[0] will be a "person" and A[1] will be a "specializations" Object

View using JSTL

${objectArray[0].salutationText}. ${objectArray[0].nameWithInitials}
${objectArray[1].specializationText}



Code for situation 2

SQLQuery query = session.createSQLQuery(sql);
query.addEntity("session", Entity.Session.class);
query.addEntity("person", Person.class);

list = query.list();
// this return List of Arrays
// where L[n] A[0] -- "session" , A[1] -- "person"

Iterate using JSTL


${p[0].sessionId}
${p[0].sessionDate}
${p[1].name}
${p[1].address}





Share Article : Hibernate querying and iteration using JSTL
Share/Save/Bookmark