Bindu Sanju

Greenhorn
+ Follow
since Feb 23, 2006
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Bindu Sanju

HI Any body have idea how to display PDF file in IFrame using Struts action. File should access from server

server means it will be available under /script_root/PDF/example.pdf , this file should take from action & display in IFrame JSP.

Please help me about this .
14 years ago
HI,
I am new for hibernate, while executing main method I am getting nullpointer exception. please some body guide me whats the wrong in my code.

package roseindia.tutorial.hibernate;

import java.io.File;

import org.hibernate.Hibernate;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;


/**
* @author Deepak Kumar
*
* http://www.roseindia.net
* Hibernate example to inset data into Contact table
*/
public class FirstExample {
public static void main(String[] args) {
Session session = null;

try{
// This step will read hibernate.cfg.xml and prepare hibernate for use
System.out.println("getEventInfo");
File file = new File("D:\\bea\\user_projects\\w4WP_workspaces\\Untitled\\Hyber\\hibernate.cfg.xml"); //yu see I have used full path
// This is my first run I will chenge to relative path later
System.out.println(file.exists());

SessionFactory sessionFactory = new Configuration().configure(file).buildSessionFactory();
if(sessionFactory == null) {
System.out.println("NULL"); //Testing it
}
else {
System.out.println("NOT NULL");
}

//SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
System.out.println("Sessiong Factory After");
session =sessionFactory.openSession();
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record");
Contact contact = new Contact();
contact.setId(3);
contact.setFirstName("Deepak");
contact.setLastName("Kumar");
contact.setEmail("[email protected]");
session.save(contact);
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
session.flush();
session.close();

}

}

}

Error is

getEventInfo
true
Exception in thread "Main Thread" java.lang.NullPointerException
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:52)
Hi,

Any body tell me how to export data from Jsp to Excel file? If some body have example please send me.

Scenario is

I have the report around 8 rows and 100 colums, when I clicke the button called Export to Excel, need to display the same report to Excel.

Please help me some body...

Waiting for + positive response.

Regards,
Sanju.
17 years ago
JSP
HI,
Paging means suppose if I fetch the 100 rows. I want to make 100 rows in 10 pages. Each page 10 rows. First,Next,Previous,Last. based on selection I want to display.

Hope will get the positive response from you guys,

Sanju.
17 years ago
JSP
Hi,
Any body please help me, how to do the paging in jsp. Plese send me some body sample code for that.

Regards,
Sanju.
[ May 28, 2007: Message edited by: Bear Bibeault ]
17 years ago
JSP
Thanks Michael Labuschagne

Its working fine and thanks for your suggestion.

Regards,
Sanju.
17 years ago
HI ,
See the below code, I am comparing two arraylist values and getting the correct result while comparing equal. in bello example
I took the values ArrayList a1=a,b,c,d,e and ArrayList a2=a,b,c.
If I compare a1==a2 result : a,b,c is comming correctly. if I try to compare not equal position ,I want to get the data d,e. If any body know please modify the code and send me back.

Thank you advanced..

ArrayList a1=new ArrayList();
ArrayList a2=new ArrayList();
a1.add("a");
a1.add("b");
a1.add("c");
a1.add("d");
a1.add("e");
a2.add("a");
a2.add("b");
a2.add("c");

for(int i=0;i<a1.size();i++){
String str1 = (String) a1.get(i);
for(int j=0;j<a2.size();j++){
String str2 = (String) a2.get(j);
//int result = str1.compareTo(str2);
// if (result == 0)
//System.out.println(str1+ " = " + str2);
//else if (result > 0)
//System.out.println(str1+ " > " + str2);
if (str2.equalsIgnoreCase(str1))
System.out.println(str1);

}

}
17 years ago
Thanks for your response, but still its not working, I dont know whats the reason.
17 years ago
Hi Garett Rowe,

Thanks for your response. I tried what ever you mentioned, I am not able to compile , the error message is showing like

Error : The Operator (+) is undefined for the argument type(s) Double,Integer.

As per my knoledge it wont work out like this way.

If possible can you try in your local system Same code.

Thank you
18 years ago
Hi,

See the Below example, I added the values in ArrayList.These values I am fetching in loop. These iterator values I want to get it cumulative way. Values are dynamic. I am expecting the result like below

Actual value cumulative value

10 --------------- 10
20 --------------- 30(10+20)
30 --------------- 60(30+30)
50 --------------- 110(60+50)
80 --------------- 190(80+110) like result I am expecting.

Please see the below code and change if any modification required.

int value;
int A1=30;
int A2=300;
int B1=40;
int B2=400;
int C1=20;
int C2=200;
int D1=10;
int D2=100;
int tots=A1+A2;
int tot = 0;
int to = 0;
Bean b=new Bean();
ArrayList al=new ArrayList();
al.add(new Integer(A1));
al.add(new Integer(B1));
al.add(new Integer(C1));
al.add(new Integer(D1));
Iterator it=al.iterator();
for(int i=0;i<al.size();i++){
b.setObjValue(al.get(i));
Integer k= (Integer) b.getObjValue();
System.out.println(b.getObjValue()+" -------------- "+k );
double d=0;
d=d+k;
}


Awating for any + ve response with result.
18 years ago
Hi Vijaishankar,

I write the colde like this , I am getting exception, please help me.


--------sender file ---------------

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.Servlet;
import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
* @version 1.0
* @author
*/
public class URLSender extends HttpServlet implements Servlet {


public void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {


try {

ArrayList aList = new ArrayList();
aList.add("1");
aList.add("2");
aList.add("3");
aList.add("4");
aList.add("5");
aList.add("6");
aList.add("7");
aList.add("8");
aList.add("9");

URL aURL = new URL("http://localhost:9080/GUTA/URLReceiver");
System.out.println("URL : "+aURL);
URLConnection aConnection = aURL.openConnection();
System.out.println("URL COnnection : "+aConnection);
aConnection.setDoInput(true);
aConnection.setDoOutput(true);
aConnection.setUseCaches(false);
aConnection.setDefaultUseCaches(false);
aConnection.setRequestProperty("Content-Type",
"application/octet-stream");

ObjectOutputStream out = new ObjectOutputStream(aConnection
.getOutputStream());
out.writeObject(aList);
out.flush();
out.close();
System.out.println("End of the file");
ObjectInputStream in = new ObjectInputStream(aConnection.getInputStream());
String text = (String) in.readObject();
System.out.println(text);
} catch (Exception e) {
e.printStackTrace();
}
}

}



-----------receiver file in different application---------

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OptionalDataException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
import java.util.List;

import javax.servlet.Servlet;
import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
* @version 1.0
* @author
*/
public class URLReceiver extends HttpServlet implements Servlet {


public void service(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/html");
PrintWriter out=resp.getWriter();
out.println("Hi this is Receiver URL");
System.out.println("Hi this is Receiver URL");

ObjectInputStream resultStream = null;
ObjectOutputStream sendStream = null;
List results = null;
try {
resultStream = new ObjectInputStream(req.getInputStream());
results = (List) resultStream.readObject();
resultStream.close();
sendStream = new ObjectOutputStream(resp.getOutputStream());
//sendStream.writeObject(String.valueOf(results.size()));
System.out.println("Hi this is Receiver Size "+String.valueOf(results.size()));
sendStream.flush();
sendStream.close();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}



/*try {

resp.setContentType("text/html");
PrintWriter out=resp.getWriter();
out.println("Hi this is Receiver URL");
System.out.println("Hi this is Receiver URL");















//URL userloginservlet = new URL("http://localhost:9080/DEN/URLSender");
//System.out.println("URL : "+userloginservlet);
//URLConnection servletConnection = userloginservlet.openConnection();
//ObjectOutputStream oos = new ObjectOutputStream(servletConnection.getOutputStream());
ObjectInputStream ois = new ObjectInputStream(req.getInputStream());
DataBean p = (DataBean) ois.readObject();
while(true){

System.out.println("Name Value is : "+p.getName());
System.out.println("Pass Value is : "+p.getPass());
}


//DataBean db=new DataBean();
//db.setName("Yandra");
//db.setPass("ramsea");
//oos.writeObject(db);

//ObjectInputStream ois = new ObjectInputStream(servletConnection.getInputStream());
////outs = servletConnection.getOutputStream();
//DataBean db;
//db = (DataBean) ois.readObject();
//db.setName("Yandra");
//db.setPass("ramsea");
//System.out.println("URL COnnection : "+servletConnection);





} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
*/



}

}


---------exception-------------------

[4/17/07 15:42:54:000 CDT] 60e0c639 WebGroup E SRVE0026E: [Servlet Error]-[URLReceiver]: java.lang.IllegalStateException: Writer already obtained
at com.ibm.ws.webcontainer.srt.SRTServletResponse.getOutputStream(SRTServletResponse.java:490)
at URLReceiver.service(URLReceiver.java:41)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at com.ibm.ws.webcontainer.servlet.StrictServletInstance.doService(StrictServletInstance.java:110)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet._service(StrictLifecycleServlet.java:174)
at com.ibm.ws.webcontainer.servlet.IdleServletState.service(StrictLifecycleServlet.java:313)
at com.ibm.ws.webcontainer.servlet.StrictLifecycleServlet.service(StrictLifecycleServlet.java:116)
at com.ibm.ws.webcontainer.servlet.ServletInstance.service(ServletInstance.java:283)
at com.ibm.ws.webcontainer.servlet.ValidServletReferenceState.dispatch(ValidServletReferenceState.java:42)
at com.ibm.ws.webcontainer.servlet.ServletInstanceReference.dispatch(ServletInstanceReference.java:40)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.handleWebAppDispatch(WebAppRequestDispatcher.java:948)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.dispatch(WebAppRequestDispatcher.java:530)
at com.ibm.ws.webcontainer.webapp.WebAppRequestDispatcher.forward(WebAppRequestDispatcher.java:176)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.doForward(WebAppInvoker.java:79)
at com.ibm.ws.webcontainer.srt.WebAppInvoker.handleInvocationHook(WebAppInvoker.java:201)
at com.ibm.ws.webcontainer.cache.invocation.CachedInvocation.handleInvocation(CachedInvocation.java:71)
at com.ibm.ws.webcontainer.srp.ServletRequestProcessor.dispatchByURI(ServletRequestProcessor.java:182)
at com.ibm.ws.webcontainer.oselistener.OSEListenerDispatcher.service(OSEListener.java:334)
at com.ibm.ws.webcontainer.http.HttpConnection.handleRequest(HttpConnection.java:56)
at com.ibm.ws.http.HttpConnection.readAndHandleRequest(HttpConnection.java:610)
at com.ibm.ws.http.HttpConnection.run(HttpConnection.java:431)
at com.ibm.ws.util.ThreadPool$Worker.run(ThreadPool.java:593)
18 years ago
HI Bill,

Thank you for your time. do you have any sample code ? Else please could you tell me few steps how to proceed.

I told you data is huge..more thank 5000+ rows will populate..

Regards,
Sanju
18 years ago
I am trying to send the object from one web application to another web application. Current both applications are in same server, future might be in different servers. Data is more than 5000+ fields. It should work with out effecting performance.

Please suggest some body how to work on this.
18 years ago
HI Poul/Mark,

THanks for your reply, I got stuck up this below code, I am getting null pointer exception in this level. in this folder *.cfg.xml file also available.but still its throwing null pointer exception.


// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();
HI I got the exception while using this below code.

// This step will read hibernate.cfg.xml and prepare hibernate for use
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
session =sessionFactory.openSession();

Configuration cfg = new Configuration();
cfg.addFile("/bin/hibernate.cfg.xml");
SessionFactory sesfact=(SessionFactory) cfg.configure().buildSessionFactory();
session=sesfact.openSession();

System.out.println("session : "+session);
//Create new instance of Contact and set values in it by reading them from form object
System.out.println("Inserting Record");
Contact contact = new Contact();
contact.setId(6);
contact.setFirstName("Deepak");
contact.setLastName("Kumar");
contact.setEmail("[email protected]");
session.save(contact);
System.out.println("Done");
}catch(Exception e){
System.out.println(e.getMessage());
}finally{
// Actual contact insertion will happen at this step
session.flush();
session.close();


java.lang.NullPointerException
at roseindia.tutorial.hibernate.FirstExample.main(FirstExample.java:45)
Exception in thread "main"