Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot call a servlet, all other working

Status
Not open for further replies.

mydavor

Programmer
Mar 21, 2004
41
0
0
AU
The following piece of code cannot initialise any servlet, although all servlets used, exist in the given directory ( ie %CATALINA_HOME%\webapps\eDevPro\WEB-INF\classes) and although they can be called from applets.
Can you please, have a sanity check. Thanks in advance

public class DPDataSelectionServ extends HttpServlet
{
....
private Vector callInterServlet(String lStringServletName,Vector lVectorArgv, HttpSession httpsession,HttpServletRequest req)
{
try{
DPDataSelectionServInterface dataTabbedPane = (DPDataSelectionServInterface)
getServletConfig().getServletContext().getServlet(lStringServletName);

if(dataTabbedPane ==null) //Servlet not initialised
{
//Making fresh url connection to servlet, this will initialise the servlet

try{
URL urlservlet = new URL(" DPUtility.println(" URLConnection urlConnection = urlservlet.openConnection();
urlConnection.connect();

//urlConnection
errorLog(req.getServerName() + req.getServerPort());
DPUtility.println(req.getServerName() + " " + req.getServerPort());


DPUtility.println("calling dataTabbedPane");
dataTabbedPane = (DPDataSelectionServInterface) getServletConfig().getServletContext().getServlet(lStringServletName);

if(dataTabbedPane==null)
{
DPUtility.println("dataTabbedPane==null exit callInterServlet");
return null;
}
DPUtility.println("Servlet Loaded :"+ lStringServletName);

}catch(Exception eUnableToLaodApplet) {
DPUtility.println("DPDataSelectionServ 1B " + "unableToLoadApplet"+lStringServletName + " " + eUnableToLaodApplet);
eUnableToLaodApplet.printStackTrace();
return null;
}

}

Vector lVectorData = new Vector();
lVectorData.addElement("true");
Vector temp = dataTabbedPane.getInitData(lVectorArgv,httpsession);
lVectorData.addElement(temp);
errorLog("CALLENDS :"+ lStringServletName);
return lVectorData;
}catch(Exception eInterServ){
return null;
}
}
}
 
Some suggestions:

when you build the url, use: req.getContextPath() for the location of your application.

I could not see that you use port 8080, if you use tomcat (I do not exactly know what req.getServerName() returns). How do the urls look? Try to copy them in your browser.

Sjakie

----------
Yes, the world is full of strange people.
 
Thanks for the tip, I can open the sevlets from browser, using a html, so the path is correct.
Sadly I found the following, so I'll have to think of a workaround.

On ir says:
getServlet(java.lang.String name)
Deprecated. As of Java Servlet API 2.1, with no direct replacement.
This method was originally defined to retrieve a servlet from a ServletContext. In this version, this method always returns null and remains only to preserve binary compatibility. This method will be permanently removed in a future version of the Java Servlet API.

In lieu of this method, servlets can share information using the ServletContext class and can perform shared business logic by invoking methods on common non-servlet classes.

And also:

getServlet() is deprecated As of Java Servlet API 2.1 with no replacement and will always return null.
You should change both your servlet and the admin servlet.
use getServletContext().setAttribute()...
You can find example in the java tutorial
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top