Search This Blog

Showing posts with label JSP. Show all posts
Showing posts with label JSP. Show all posts

Wednesday, 16 June 2010

trimDirectiveWhitespaces with JSTL

While using JSP I always use JSTL to avoid any use of java on the JSP itself. To get a quick world cup 2010 tipping competition up and running I found that my response pages using JSTL contained just way to much white space. Luckily in the JSP 2.1 world we can use the page directive trimDirectiveWhitespaces to easily remove that unwanted white spaces. Basically it's done as follows

<%@ page
contentType="text/html;charset=windows-1252"
trimDirectiveWhitespaces="true" %>

So to see how well this works simply use the code below in JDeveloper 10.1.3 (JSP 2.0) and then in JDeveloper 11g (JSP 2.1) and view the source of the page after running it.

Note: When running this code in JDeveloper 10.1.3 you will have to remove trimDirectiveWhitespaces="true" as it does not support that.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ page contentType="text/html;charset=windows-1252" trimDirectiveWhitespaces="true" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
<title>JSP 2.1 - trimDirectiveWhitespaces JSTL demo</title>
</head>
<body>
<h2>JSP 2.1 - trimDirectiveWhitespaces JSTL demo</h2>

<c:forEach var="row" begin="1" end="5">
<c:choose>
<c:when test="${row == 1}">
<font color="green">
<c:out value="At row 1"/>
</font>
<br />
</c:when>
<c:otherwise>
<c:choose>
<c:when test="${row != 1}">
<font color="Red">
<c:out value="Not at row 1"/>
</font>
</c:when>
<c:otherwise>
<c:out value="Should never get here"/>
</c:otherwise>
</c:choose>
<br />
</c:otherwise>
</c:choose>
</c:forEach>

</body>
</html>

Tuesday, 17 March 2009

Getting debug output from utl_dbws PLSQL package

When calling web services from an oracle database you can use utl_dbws package. There are times though that you need to debug it to determine why it may be failing. This can be achieved as follows.

call dbms_java.set_output(100000);

Example output from a SQL file as follows. This example is calling a JAXRPC 1.4 web service from OAS 10.1.3.4

SQL:

set serveroutput on

call dbms_java.set_output(100000);

-- call web service methods here now for end point below
-- http://beast.au.oracle.com:7777/wsrocks/DemoWSSoapHttpPort
-- WSDL = http://beast.au.oracle.com:7777/wsrocks/DemoWSSoapHttpPort?WSDL

prompt
prompt Calling method todaysDate from web service
prompt

select PasWS102.todaysDate from dual;

prompt
prompt Calling method echoString from web service
prompt

select PasWS102.echoString('Pas') from dual;

Output:


SQL*Plus: Release 10.2.0.1.0 - Production on Tue Mar 17 08:56:38 2009

Copyright (c) 1982, 2005, Oracle. All rights reserved.

Enter password: *****

Connected to:
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit Production
With the Partitioning, OLAP, Data Mining and Real Application Testing options

Call completed.

Calling method todaysDate from web service


TODAYSDATE
----------------------------------------------------------------------------------------------------
Tue Mar 17 07:57:37 EST 2009

ServiceFacotory: oracle.j2ee.ws.client.ServiceFactoryImpl@bb101899
WSDL: null
Service: oracle.j2ee.ws.client.BasicService@ce6cb3d5
*** Created service: -677524827 - oracle.jpub.runtime.dbws.DbwsProxy$ServiceProxy@2968f5e4 ***
ServiceProxy.get(-677524827) = oracle.jpub.runtime.dbws.DbwsProxy$ServiceProxy@2968f5e4
** Calling web service method {todaysDate} **
setProperty(javax.xml.rpc.soap.http.soapaction.use, true)
setProperty(javax.xml.rpc.soap.http.soapaction.uri, http://pas.au.ws//todaysDate)
setProperty(javax.xml.rpc.soap.operation.style, document)
** Invoking web service method {todaysDate} **
Attribute 0: http://pas.au.ws/types/: xmlns, http://pas.au.ws/types/
createElement(todaysDateElement,null,http://pas.au.ws/types/)
Attribute 0: http://pas.au.ws/types/: xmlns, http://pas.au.ws/types/
request:

response:

Tue Mar 17 07:57:37 EST 2009

** Successfully invoked web service method {todaysDate} **

Calling method echoString from web service


PASWS102.ECHOSTRING('PAS')
----------------------------------------------------------------------------------------------------
Pas

ServiceFacotory: oracle.j2ee.ws.client.ServiceFactoryImpl@bb101899
WSDL: null
Service: oracle.j2ee.ws.client.BasicService@d05260ad
*** Created service: -677524826 - oracle.jpub.runtime.dbws.DbwsProxy$ServiceProxy@7789dbfd ***
ServiceProxy.get(-677524826) = oracle.jpub.runtime.dbws.DbwsProxy$ServiceProxy@7789dbfd
** Calling web service method {echoString} **
setProperty(javax.xml.rpc.soap.http.soapaction.use, true)
setProperty(javax.xml.rpc.soap.http.soapaction.uri, http://pas.au.ws//echoString)
setProperty(javax.xml.rpc.soap.operation.style, document)
** Invoking web service method {echoString} **
Attribute 0: http://pas.au.ws/types/: xmlns, http://pas.au.ws/types/
createElement(echoStringElement,null,http://pas.au.ws/types/)
Attribute 0: http://pas.au.ws/types/: xmlns, http://pas.au.ws/types/
dbwsproxy.element.node.child.0: 1, null
createElement(s,null,http://pas.au.ws/types/)
dbwsproxy.text.node.child.0: 3, Pas
request:

Pas

response:

Pas

** Successfully invoked web service method {echoString} **
SCOTT@linux10g>

Thursday, 24 January 2008

Precompiling JSP's within an EAR file using OJSPC

You can precompile JSP files to avoid the hassle of compiling the JSP on it's first request into a servlet class file at runtime prior to deployment using "ojspc". The key is how to check that it has indeed done that. His an example:

Step 1: verify EAR file
- jar -tvf jspcompile.ear
       487 Thu Jan 24 11:26:22 EST 2008 META-INF/application.xml
226 Thu Jan 24 11:26:12 EST 2008 META-INF/orion-application.xml
2066 Thu Jan 24 11:26:22 EST 2008 jspcompile.war
Step 2: Compile using ojspc
- ojspc jspcompile.ear
    Detected archive, now processing contents of jspcompile.ear...
Setting up temp area...
Expanding archive in temp area...
Detected archive, now processing contents of /tmp/tmp56123/jspcompile.war...
Setting up temp area...
Expanding archive in temp area...
Creating /tmp/tmp56123/jspcompile.war ...
Removing temp area...
Creating /u01/pas/tars/sr/jspcompile.ear ...

Removing temp area...
Step 3: Verify compiled JSP JAR file is present within WEB-INF\lib

Extract EAR file
jar -xvf jspcompile.ear
     inflated: META-INF/application.xml
inflated: META-INF/orion-application.xml
inflated: jspcompile.war
Extract WAR File
jar -xvf jspcompile.war
     inflated: Page1.jsp
inflated: Page2.jsp
inflated: WEB-INF/classes/META-INF/orion-application.xml
inflated: WEB-INF/web.xml
inflated: WEB-INF/lib/__oracle_jsp_jspcompile.jar

As you can see OJSPC has created a file called "__oracle_jsp_jspcompile.jar" with the precompiled JSP source files ready to be run. More info on this is in the online documentation for OAS 10.1.3.x

http://download.oracle.com/docs/cd/B31017_01/web.1013/b28961/ojspc.htm#sthref209
Precompiling JSPs within a WAR File