accessing values of java variables

86 views
Skip to first unread message

rb12

unread,
Feb 8, 2008, 6:24:00 AM2/8/08
to json-taglib
hi!!!am a newbie to JSON....am still learning the semantics.
Am accessing values in java variables through JSON taglib.instead of
printing the value at "${p.col}"....Its printing "${p.col}" and is not
printing its value.

sundar rajan

unread,
Feb 8, 2008, 6:26:47 AM2/8/08
to json-...@googlegroups.com
Hai,
             Can u please send me the code what u had written.

rb12

unread,
Feb 8, 2008, 6:57:51 AM2/8/08
to json-taglib
This is the jsp code:

<%@ page language="java" %>
<%@ page import="org.apache.poi.hssf.usermodel.*" %>
<%@ page import="java.io.PrintWriter" %>
<%@ page import="java.io.OutputStream" %>
<%@ page import="poi2.POIExample" %>
<%@ taglib prefix="json" uri="http://www.atg.com/taglibs/json" %>

<jsp:useBean id="example" class="poi2.POIExample"/>
<html>
<head>Testing Page</head>
<h1>HI</h1>
<body>
<% POIExample obj = new POIExample();
%>

<json:object>
<json:property name="col" value="${obj.name}"/>
</json:object>
<json:object>
<json:property name="outer" value="foo"/>

<json:object name="inner">
<json:property name="innerProp1" value="val1"/>
<json:property name="innerProp2" value="val2"/>

<json:object name="inner2">
<json:property name="inner2Prop1" value="in2p1"/>
<json:property name="inner2Prop2" value="in2p2"/>
</json:object>

</json:object>
</json:object>

</body>
</html>


n the java code is:(the "name" variable)

package poi2;

import org.apache.poi.poifs.filesystem.POIFSFileSystem;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import java.io.PrintWriter;
import java.lang.Exception;
import java.util.Iterator;
/**
* A simple POI example of opening an Excel spreadsheet
*/
public class POIExample {

public String name;

public static void main( String args[] ) {
POIExample p = new POIExample();

p.read();
}

public void read(){
try {

InputStream input =
POIExample.class.getResourceAsStream( "qa.xls" );
POIFSFileSystem fs = new POIFSFileSystem( input );
HSSFWorkbook wb = new HSSFWorkbook(fs);
HSSFSheet sheet = wb.getSheetAt(0);


// Iterate over each row in the sheet
Iterator rows = sheet.rowIterator();


HSSFRow row = (HSSFRow) rows.next();
System.out.println( "Row #" + row.getRowNum() );

// Iterate over each cell in the row and print out the
cell's content
Iterator cells = row.cellIterator();


HSSFCell cell = (HSSFCell) cells.next();
System.out.println( "Cell #" +
cell.getCellNum() );


name = cell.getRichStringCellValue().toString();


}catch ( Exception ex ) {
ex.printStackTrace();

sundar rajan

unread,
Feb 8, 2008, 7:06:40 AM2/8/08
to json-...@googlegroups.com

Hai ,
         just try it this..... i think you may get values....
In java class u have set the value for the name am right.if u set the value you can get the value sure.

       <json:property name="col" value="${example.name}"/>

rb12

unread,
Feb 8, 2008, 8:17:44 AM2/8/08
to json-taglib
i did set a value to "name" variable..Even if i hard code the
value,the result is the same!
Sorry for all the trouble!!!!!!
thanx again!
> <json:property name="col" value="${example.name <http://obj.name/>
>
> }"/>

James Wiltshire

unread,
Feb 16, 2008, 4:23:55 AM2/16/08
to json-taglib
It sounds like EL isn't enabled within your webapp. You need to ensure
that the web-app version declared in your web.xml file is at least
version 2.4 so that you're using JSP2.0, where EL will be supported
natively within your JSPs.
Check out this thread from the Sun Developer forums which contains an
example of the web.xml web-app declaration you need.
http://forum.java.sun.com/thread.jspa?threadID=5146051&messageID=9544792

Regards
James Wiltshire
Reply all
Reply to author
Forward
0 new messages