Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Problem in Java Programing

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 :

<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.

Former Member
Not what you were looking for? View more on this topic or Ask a question