Hi all,
Am working on WebSphere Application Server 2.0 and am
facing some problems because of compatiblity problems
wrt Servlets & JSP, as it supports Servlets 2.0 & JSP
0.91.
Therefore I cannot use the following methods:
a)request.setAttribute()
b)getServletConfig().getServletContext().getRequestDispatcher("URL",request)
c)request.getAttribute()in the JSP
WAS 2.0 provides alternative in the following way:
a)((com.sun.server.http.HttpServiceRequest)request).setAttribute()
b)((com.sun.server.http.HttpServiceResponse)response).callPage("URL",request);
c)Use beans to pass the parameter in the servlet & get
it in the JSP
I have written a sample code which passes a string
"Hello" in the servlet to a bean & the JSP displays it
by the get() method in the bean.
***************************************************
This is the WASHelloJSP.jsp
<HTML>
<HEAD>
</HEAD>
<BODY>
<BEAN NAME="WHB" TYPE="HelloBean" INTROSPECT=NO
CREATE=NO SCOPE=REQUEST>
</BEAN>
<SCRIPT runat=server>
String Hello="HiJSP";
</SCRIPT>
<H3> The original string was: <%= Hello %></H3>
<% Hello=WHB.getHello(); %>
<H3> The passed string was: <%= Hello %></H3>
</BODY>
</HTML>
******************************************************
This is the WASHelloServlet.java
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.beans.*;
public class WASHelloServlet extends HttpServlet
{
String Hello="Hello";
HelloBean WHB = null;
public void doGet(HttpServletRequest request,
HttpServletResponse response)throws
ServletException,IOException
{
try
{
WHB =
(HelloBean)Beans.instantiate(getClass().getClassLoader(),"HelloBean");
WHB.setHello("Hello all");
((com.sun.server.http.HttpServiceRequest)request).setAttribute("WHB",WHB);
((com.sun.server.http.HttpServiceResponse)response).callPage("/IBMWebAS/samples/WASHelloJSP.jsp",request);
}
catch(ClassNotFoundException e)
{}
}
}
******************************************************
This is the HelloBean.java
import java.io.*;
import java.util.*;
public class HelloBean implements Serializable
{
String Hello="Hi";
public void setHello(String HelloTemp)
{
this.Hello=HelloTemp;
}
public String getHello()
{
return Hello;
}
}
*****************************************************
This works.
But the problem is as follows:
The Beans(HelloBean.java),
Servlets(WASHelloServlet.java) & the
JSP(WASHelloJSP.jsp) have to be in the same directory,
which will involve crouding the directory(in this case
: WebSphere/Appserver/samples)
Could you please treat this query as urgent & reply to
the same.
Mythili
__________________________________________________
Do You Yahoo!?
Talk to your friends online with Yahoo! Messenger.
http://messenger.yahoo.com
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html