wood burning stoves 2.0*
The moose likes Servlets and the fly likes JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "JSP" Watch "JSP" New topic
Author

JSP

Friend
Ranch Hand

Joined: Nov 23, 2000
Posts: 67

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.
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?
3.In JSP when I used the following code to move to other pages:
code:
<html> <script language="javascript">
function f1()
{
formname.buttonname.action="xx.jsp";
formname.buttonname.submit();
}
function f2()
{
formname.buttonname.action="yy.jsp";
formname.buttonname.submit();
}
</script>
<%@ page language="java" %>
<body>
<input type=submit value=gotoxx onClick="f1()">
<input type=submit value=gotoyy onClick="f2()">
</body>
</html>
When I clicked to the button "gotoxx" I want to move to the xx jsp and when clicked the "gotoyy" I want to move the "gotoyy".But this code didn't work.What is the correct coding for this? Can you give me any idea?
Matthew X. Brown
Ranch Hand

Joined: Nov 08, 2000
Posts: 165
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP
 
Similar Threads
problem with form submission
JavaScript page load get value of anchor
Display of Latin Characters
on button click value is not getting
document.write doesn't work in netscape