hi,
i deployed a webapplication(wapp1) having input.html and a servlet(Servlet1) in tomcat web server. The form input.html just accepts a text and when u click on the button click the request is sent to servlet in wapp1. The request is redirected to a servlet(Servlet2) which is in a webapplication(wapp2) deployed on weblogic application server...the response is given to the browser using servlet in wapp2 deployed in weblogic server...but when i try to do this i get java.lang.NullPointerException...
The code is here...

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class Servlet1 extends HttpServlet{

	public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{
		String s1=req.getParameter("uname");
		res.sendRedirect("http://localhost:7001/wapp2/srv2?user="+s1);
	}//end of doGet
}

web.xml is here for first servlet in tomcat

<web-app>
 <servlet>
   <servlet-name>dum</servlet-name>
   <servlet-class>Servlet1</servlet-class>
 </servlet>
 <servlet-mapping>
   <servlet-name>dum</servlet-name>
   <url-pattern>/srv1</url-pattern>
 </servlet-mapping>
</web-app>

//and this is input.html in web application 1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>

</HEAD>

<BODY>
<center>
<h2>
<form action="srv1">
Username:<input type=text name="uname"><br>
<input type=submit value="click">
</form>
</h2>
</center>

</BODY>
</HTML>

The above code is in wapp1 deployed in tomcat server.

The following code is in web application deployed in weblogic server

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class Servlet2 extends HttpServlet{

	public void doGet(HttpServletRequest req,HttpServletResponse res)throws ServletException,IOException{
		PrintWriter pw=res.getWriter();
		String s=req.getParameter("user");
		pw.println("welcome "+s);
		pw.close();
	}//end of doGet

}
//the web.xml for this servlet
<web-app>
 <servlet>
   <servlet-name>dum</servlet-name>
   <servlet-class>Servlet2</servlet-class>
 </servlet>
 <servlet-mapping>
   <servlet-name>dum</servlet-name>
   <url-pattern>/srv2</url-pattern>
 </servlet-mapping>
</web-app>

The exception is

Error 500--Internal Server Error
java.lang.NullPointerException
at java.util.Hashtable.put(Hashtable.java:389)
at weblogic.servlet.internal.WebAppServletContext.setAttribute(WebAppServletContext.java:669)
at Servlet2.doGet(Servlet2.java:11)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)

Thanks in advance.....

Recommended Answers

All 2 Replies

and what is line 11?

and what is line 11?

Line no 11 is same as line no 10

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.