• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JSP

 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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?
 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
We can walk to school together. And we can both read this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic