on 05-15-2006 4:46 AM
Hi,
I developed a program J2EE Web Module Project. In which when i enter a vendor number it has to get the details of the particular Vendor Name.
But when i deployed it is throwing an exception "NullPointerException". But I could not recognize it. Please let me know where is the error.
Here is my HTML and Servlet Code ZTEST_VENDOR is my BAPI (RFC):
<html>
<head>
<title> Vendor Details</title>
<script language="JavaScript">
function randomnumber()
{
var r=Math.floor(Math.random()*1111);
if ( r!=0)
{
document.form1.rand.value=r;
}
}
function getVendorDetails()
{
document.location = "http://localhost:8880/vendor/Servlet";
}
</script>
</head>
<body bgcolor="#eeeff8" onLoad = "javascript:randomnumber();">
<center>
<hr>
<h1>Enter the Vendor Number</h1>
<hr>
</center>
<form name=form1 action="Servlet" method=post>
<center>
<input type="text" name="vendno">
<input type="Submit" value="Submit">
<input type=hidden name="rand">
</center>
</form>
</body>
</html>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
</BODY>
</HTML>
and Servlet code is as below :
package vendor.pkg;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.sap.mw.jco.IRepository;
import com.sap.mw.jco.JCO;
import com.sap.mw.jco.IFunctionTemplate;
public class VendorServlet extends HttpServlet {
PrintWriter pw;
public void doPost(HttpServletRequest req, HttpServletResponse res) {
int num = Integer.parseInt(req.getParameter("rand"));
String no, name, city, po;
String SID = "R" + num;
String vendno = req.getParameter("vendno");
IRepository repository;
// The repository we will be using
try {
// Add a connection pool to the specified system
JCO.addClientPool(
SID,
100,
"200",
"pavan",
"pavan",
"EN",
"sapdev",
"00");
repository = JCO.createRepository("MYRepository", SID);
pw.println("Connection got");
IFunctionTemplate ftemplate =
repository.getFunctionTemplate("ZTEST_VENDOR");
JCO.Function function = new JCO.Function(ftemplate);
JCO.Client client = JCO.getClient(SID);
JCO.ParameterList input = function.getImportParameterList();
input.setValue(vendno, "LIFNR");
client.execute(function);
JCO.Structure ret =
function.getExportParameterList().getStructure("RETURN");
pw = res.getWriter();
pw.println(
"<html><head><title>VendorDetails</title></head><body bgcolor=#eeeff8><center><hr><h1>Customer Details</h1><hr>");
JCO.Table vend = function.getTableParameterList().getTable("ITAB");
for (int i = 0; i < vend.getNumRows(); i++) {
vend.setRow(i);
no = vend.getString("LIFNR");
name = vend.getString("NAME1");
city = vend.getString("ORT01");
po = vend.getString("PFACH");
pw.println(
"<table border=1><tr><td><B>Vendor Number</B></td><td>"
+ no
+ "</td></tr><tr><td>"
+ "<B>Customer Name</B></td><td>"
+ name
+ "</td></tr><tr><td>"
+ "<B>Customer Address</B></td><td></tr>"
+ "<tr><td> </td><td><B>City</B></td><td>"
+ city
+ "</td></tr>"
+ "<tr><td> </td><td><B>District</B></td><td>"
+ po
+ "</td></tr>+</table>");
pw.println(
"<form name=form1 action='Index.html' method=get><input type=submit value='Back'></form></center></body></html>");
}
} catch (Exception E) {
pw.println(E);
}
}
}
Please help me out.
Thanks,
Pavan.
Message was edited by: Pavan Panduru
hi
Are u getting the NullpointerException on deployment or
while running the program .Also as amol had mentioned would be better if you could check the lof file sa nd post the stackTrace here
hope this helps, please mark helpful answers
regards
rajeshkr
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
This is the error i am getting, iam not deploying it into the J2EE application server i am using JBOSS as my application server.
Started in 18s:610ms
2006-05-15 10:31:36,426 ERROR [org.jboss.web.localhost.Engine] StandardWrapperValve[VendorServlet]: Servlet.service() for servlet VendorServlet threw exception
java.lang.NullPointerException
at vendor.pkg.VendorServlet.doPost(VendorServlet.java:71)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:237)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:75)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:186)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:157)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:214)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:152)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:66)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:54)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:137)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:118)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:102)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.core.StandardValveContext.invokeNext(StandardValveContext.java:104)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:520)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:929)
at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:160)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:799)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:705)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:577)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:683)
at java.lang.Thread.run(Thread.java:534)
Hi Pavan,
It seems like you have not intialized the JCo pool, to do that do the following initialization before adding the client to the pool.
JCO.Pool pool = JCO.getClientPoolManager().getPool(POOL_NAME);
The full code should look like this,
try {
JCO.Pool pool = JCO.getClientPoolManager().getPool(POOL_NAME);
if (pool == null) {
OrderedProperties logonProperties =
OrderedProperties.load("/logon.properties");
JCO.addClientPool(POOL_NAME, // pool name
5, // maximum number of connections
logonProperties); // properties
}
mConnection = JCO.getClient(POOL_NAME);
System.out.println(mConnection.getAttributes());
}
catch (Exception ex) {
ex.printStackTrace();
}
finally {
JCO.releaseClient(mConnection);
}
Since there was no pool it was giving a null pointer axception. For a detailed tutorial go to the following link,
I hope this will certailny help you.
Best regards,
Guru.
PS: Don't forget the points
pw.println("Connection got");
is the culprit.:) you have initialized pw after this statement is executed and hence the error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
101 | |
13 | |
13 | |
11 | |
11 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.