Prannav Santhosh

Greenhorn
+ Follow
since May 09, 2009
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Prannav Santhosh

Hi - Can some one explain me the Vertical / horizontal extensibility feature of SOAP , with an example ? thanks for your help..
on accessing the url ...http://localhost:9080/LearnStrutsWeb/getProduct.do , I am calling an Action class , which will in turn gets the info from a DB and populates it to a Value object (ProductTO) and in the ation iam redirecting the request to a JSP (displayAddProductForm.jsp).

The below is the code for the jsp.
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<html:errors></html:errors>
<h3>Add a product</h3>
<html:form action="/saveProduct">
<table>
<tr>
<td>Product Name:</td>
<td><html:text property="productName"/></td>
</tr>
<tr>
<td>Description:</td>
<td><html:text property="description"/></td>
</tr>
<tr>
<td>Price:</td>
<td><html:text property="price"/></td>
</tr>
<tr>
<td><html:reset/></td>
<td><html:submit>UpdateProduct</html:submit></td>
</tr>
</table>
</html:form>

</body>
</html>


The action class code.
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// Get the info from DB.
ProductTO prodto= new ProductTO();
prodto.setProductDecsription("XXXXXXXX");
prodto.setProductName("DPL");
prodto.setProductPrice("100000");

Form productForm11 = (Form)form;
productForm11.setProductName(prodto.getProductName());
productForm11.setDescription(prodto.getProductDecsription());
productForm11.setPrice(prodto.getProductPrice());

// Finish with
return mapping.findForward("success");


Struts file entry
<action path="/getProduct" type="app02a.action.GetProductAction" name="productForm" validate="false">
<forward name="success" path="/displayAddProductForm.jsp"></forward>
</action>

<form-bean name="productForm" type="app02a.form.Form"/>

question here is , when the action class executes the last line of code (mapping.findforward() ) , it redirect to teh JSP and the html fields , with in the JSP's are populated with the value , which i got from the DB. Can some one explain me , how are these fields getting populated.?

Thanks for your help.
12 years ago
Hi,

I have the below JSP (product.jsp).

<body>
<html:errors></html:errors>
<h3>Add a product</h3>
<html:form action="/saveProduct">
<table>
<tr>
<td>Product Name:</td>
<td><html:text property="productName"/></td>
</tr>
<tr>
<td>Description:</td>
<td><html:text property="description"/></td>
</tr>
<tr>
<td>Price:</td>
<td><html:text property="price"/></td>
</tr>
<tr>
<td><html:reset/></td>
<td><html:submit>Add Product</html:submit></td>
</tr>
</table>
</html:form>

</body>

In the action form , the validate method has the following logic
if(price.equals("1")){
errors.add("", new ActionError("error.price"));
}

so , in the JSP , when i enter the following value for the fields

Product Name :----> test
Description :-----> testDesc
Price:------->1

and click on the "Add Product" button , since the price file is having the value ="1" , the request gets redirect to the same product.jsp , dispaying the appropriate message( error.price ,define in the property file) in product.jsp.

Now my question is , In case of error , when the request is been redirected to the product.jsp page, why does the JSP retains the form values.

Product Name :----> test
Description :-----> testDesc
Price:------->1

and why does this happen ?

Thanks in advance.
12 years ago
Joe- thanks for your time..
12 years ago
Hi,
I have a welcome.jsp (as shown below)

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<html:form action="/Data" method="post" >
</html:form>
</body>
</html>

In the struts config.xml , I have the below entry.

<form-beans>
<form-bean name="dataForm" type="com.forms.DataForm">
</form-bean>
</form-beans>

<action-mappings>
<action path="/Data" type="com.actions.DataAction" name="dataForm">
<forward name="success" path="/Success.jsp"></forward>
</action>
</action-mappings>
The question here is , when i type in the http://localhost:9080/<webcontext>/welcome.jsp , will the DataForm object be created ?
12 years ago
I was going through the EJB2.1 spec and the below is what the spec say's (for example )
"For example, the Account enterprise bean may throw an application exception to report that a debit operation cannot be performed because of an insufficient balance. The Account bean should not use an application exception to report, for example, the failure to obtain a database connection."

If my bean access the database , for which some of the methods will throw SQLException and as per the above statement , so i should not be converting SQLException to my custom exception in my DAO layer?
In case of the stateless session bean , When client calls the create method on the remote home interface , will the ejbCreate() in the bean class be always executed ? because in one of the books its been mentione that the stateless session bean instance will be created in advance and save in to a pool , before even the client requests one.
Hi,

I am new to EJB and i have a question on looking up the local ejb.

I have a local EJB bean deployed in my RSA which is associated with a JNDI name "ejb/com/ThirdBeanLocalHome" and i am accessing the EJB from a servlet ( as part of the same EAR).

Scenario (1) -- > when i use the direct JNID name from my servlet , the look up is failing
InitialContext con = new InitialContext();
ThirdBeanLocalHome homeInt = (ThirdBeanLocalHome)con.lookup("ejb/com/ThirdBeanLocalHome");

Scenario (2) -> when i declare a refernce in the web.xml , i am able to lookup the localhome from my servlet.

Does any one know why the scenario(1) fails ?

Thanks!!
I have an EJB (Stateless session bean) and a web module as part of my EAR.
EJB is mapped to the JNDI - "ejb/ejbs/FortuneBeanHome"

Scenario (1)
========
I added this EJB project in the build path of the Web module and in the web module i have a servlet class which has the following code.

Object hmObject =con.lookup("ejb/ejbs/FortuneBeanHome");
FortuneBeanHome homeObject = (FortuneBeanHome)PortableRemoteObject.narrow(hmObject, FortuneBeanHome.class);
FortuneBean fbean = homeObject.create();

The above code works perfect. but when i use the below code

Object hmObject =con.lookup("java:comp/env/ejb/ejbs/FortuneBeanHome");

I get an exception "javax.naming.NameNotFoundException: Name comp/env/ejb not found in context "java:"

In what scenario , should i be using "java:comp/env/" ?

Thanks !!!
Hi,
I have the following code.

//My remote component interface.
public interface Test extends ILibrary,javax.ejb.EJBObject {
//no method definition here.
}



//my business interface
public interface ILibrary {

public String getName()throws RemoteException;
}


public class LibraryDelegate implements ILibrary {
ILibrary ilib=null;
LibraryDelegate(){
//lookup the ejb and get the reference to the ILibrary Interface.
}

public String getName() throws DesignException {
String s=null;
try {
s= ilib.getName();
} catch (RemoteException e) {
throw new DesignException(e.getMessage());
}

return s;
}

}

The getName() method in the above delegate class give me compilation error saying "Exception DesignExcpetion is not compatible with the throws clause in ILibrary.getName() method". Am i doing something thing wrong ? Thanks for your help.

Can some one explain me what is the advantage of using this "Business Interface" pattern ?.. Thanks for your help
Can some one let me know what is the advantage of marking the variable as private in a class and providing a interface for accessing them ? for example.
Class A {
Private int name=null;

provide agettter method for accessing the name vaiable.
}
Hi,

I am new to the struts and i was going through "Jakarta struts book" and i have a question. In this book they have described a sample Action class as below.

Public class LoginAction extends Action {

public ActionForward execute (ActionMapping map , ActionForm form ,
HttpServletRequest req , HttpServletResponse res) throws Exception{
// Line 1
IAutenticate service = new SecurityService();
service.login()
}
}

For the Line 1 , they gave the below description.
"The LoginAction" delegates the handling of business logic to another service. In this case , it relies on the SecurityService component. The SecurityService component may be a EJB or just a wrapper around JDBC code. In either way this is helpful because even if the implementation changes drastically , no code will have to change as long as the IAutenticate interface remains unchanged and is implemented by the service."

My question would be what if the Line one is replaced with the below code
SecurityService service = new SecurityService(); and not implementing an interface.

Regards,
Prannav.





14 years ago
I dont agree with you, because take a look the below code.

public void tricky1(Point arg1,Point arg2){
Point arg3 =arg1;
arg3.x=300;
arg3.y=300;


}

Then if i have one more method and from the main() method if i call tricky1() instead of tricky() , i see the below output.

X: 0 Y:0
X: 0 Y:0

X: 300 Y:300
X: 0 Y:0
I was going thorugh an artical in javaworld and Can any one help me in under standing this below concept ?

public void tricky(Point arg1,Point arg2){
arg1.x=100;
arg1.y=100;
Point temp= arg1; //1
arg1=arg2; //2
arg2=temp; //3
}


public static void main(String args[]){
Class2 c = new Class2();
Point pnt1 = new Point(0,0);
Point pnt2 = new Point(0,0);
System.out.println("X: "+pnt1.x +" Y:"+pnt1.y);
System.out.println("X: "+pnt2.x +" Y:"+pnt2.y);
System.out.println("");
c.tricky1(pnt1,pnt2);
System.out.println("X: "+pnt1.x +" Y:"+pnt1.y);
System.out.println("X: "+pnt2.x +" Y:"+pnt2.y);

}
The out put of the above program is
X: 0 Y:0
X: 0 Y:0

X: 100 Y:100
X: 0 Y:0

My question:
-------------
public void tricky(Point arg1,Point arg2){
arg1.x=100; //1
arg1.y=100; //2
Point temp= arg1; //3
arg1=arg2; //4
arg2=temp; //5
}

when we are calling the tricky method , we are passing the copy if the reference value to the method (copy of pnt1 and pnt2) and now we have arg1 and pnt1 pointing to the same Point object and similarly we have pnt2 and arg2 pointing to the same Point Object.
at //1 and //2 we are seeting x and y to a new value.
at //3 the copy of the reference variable arg1 is assigned to temp reference variable (Does it mean the arg1 , temp and pnt1 are pointing to the same Point Object ?)
at //4 copy of the arg2 is assigned to reference variable arg1 (which means the arg1.x and arg1.y in the main should print the value as zero?).
at //5 copy of the reference variable temp is assinged to arg2 (which means the arg2.x and arg2.y in the main should print the value as 100?).

Can some one explains me why i see a different out as shown below ?
The out put of the above program is
X: 0 Y:0
X: 0 Y:0

X: 100 Y:100
X: 0 Y:0

Thanks in advance.

Regards,
Prannav.