1.JSP using bean ,what is the use of "setProperty"?From where we are setting the property?Is it from an html page?Please explain a bit about it.
Answer: You are setting the properties of the actual bean class you are implementing through the jsp. You know how beans have get and set methods that need to be established? Well this is how we get and set them through the JSP. The properties will be from the HTML page possibly-but not always-you could be getting them from a database. Anyway, an example of this is a bean class that implements some shopping cart functionality. The shopping cart will save various objects of price,quantity,Order Numbers, Total Cost. End users on the web site will determine these parameters- so you need to take those parameters from the website, and use the "SetProperty" and "GetProperty" methods to setup the instantiated bean properly. Finally, you'll use the getProperty methods to return the data back-say-to confirm the order. For example, if your bean class has the following code(giving a typical shopping cart example):
here is your bean class:
public class ShoppingCart{
private
String orderNum
private int quantity
private int price
private int totalCost
public void setQuantity(int quantity){
this.quanity = quantity;
}
public int getquanity(){
return (quantity);
}
public double getTotalCost(int quantity, int price){
return(quanity*price);
}
ect ect ect....
Now lets keep it simple-here is your Html file that is sending the post request to your jsp:
<html>
<form method="POST" action="YourjspURL">
<p><input type="text" name="orderNum" size="20"></p>
<p><input type="text" name="quantity" size="20"></p>
<p><input type="text" name="price" size="20"></p>
<p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
</form>
</html>
Now here is your jsp that implements the bean that processes the information->
YourJSPURL
<jsp:useBean id="entry" class="ShoppingCart"/>
<jsp:setProperty
name="entry"
property="quantity"
value='<%=request.getParameter("quantity")%>' />
<jsp:setProperty
name="entry"
property="orderNum"
value=<%=request.getParameter("orderNum")%>'/>
<jsp:setProperty
name="entry"
property="price"
value=<%=request.getParameter("price")%>'/>
//Now you'll get to retrieve those properties-
<TABLE ALIGN="CENTER">
<TR Quanity<TH>Order_Number<TH>Price<TH>Total_Cost
<TR ALIGN="RIGHT">
<TD><jsp:getProperty name="entry" property="quantity"/>
<TD><jsp:getProperty name="entry" property="orderNum"/>
<TD><jsp:getProperty name="entry" property="price"/>
<TD><jsp:getProperty name= "entry" property="totalCost"/>
</TABLE>
I know that this code isn't complete, since I'm writing it on the fly, but it should give you an idea.....
2.When I downloaded the JSP example code from sun site I received all files with ".WAR" extension.What is ".war"?How is it extracted?
War is a Web Archive- kinda like a jar for
servlets and jsp's.
The
J2EE developers guide gives specifics as to packaging your WAR files up. Here is a link to some stuff I found on it.
http://developer.java.sun.com/developer/technicalArticles/J2EE/Intro/intro.html Your last question- I'll have to get back to you on.