• 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

send variables along with html content

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi everybody,
A JSP is converted to a servlet, and a response is sent as a html file. If I�m using a JSP to send the response can I send variables (like customer�s purchase amount so far and customer�s balance amount) along with the html content in the response and then use it to alert the customer if he /she purchases more items and his/her purchase amount is greater than the balance amount.

cheers,
Poonam K.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Poonam Kadu:
If I�m using a JSP to send the response can I send variables ...



Depends what you mean by "variables".

If you mean Java variables, then of course not. What would deal with them on the client side? Remember, from the point of view of the browser, it's getting an HTML page just like any other. The fact that it was generated with JSP is moot.

If you mean Javascript variables, then yes. You can include Javascript variables initialized to whatever value you'd like in the generated page markup.
 
Poonam Kadu
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your explanation.Now I�ve got a clear idea of what a browser understands and what it doesn�t . But now I�ve another problem�
When the user clicks on the checkout button for the first time , if purchase amount is greater than balance then the alert message �Insufficient Balance� is displayed.
Seeing this alert message the user modifies his/her purchase requests so that purchase amount is less than balance.
To modify a (purchase/sell)request , Modify.jsp and SaveChanges.java servlet are used.
SaveChanges.java makes the required changes to the Requests object(it�s a Model, shoppingcart kind of object) and forwards the httprequest to DisReq.jsp

When the user clicks on checkout button(for the 2nd time) after modifying purchase requests, the browser uses the old values of script variables puramt and balamt (used during first checkout) to check whether purchase amount< balance

<%--DisReq.jsp displays the Buy/Sell stocks requests so far placed by the user--%>
<%--Allows the user to remove or modify a desired request, place more requests and checkout--%>

<html>
<body bgcolor="#6495ed" text="#000000">

<%@ page import="java.util.*" %>
<%@ page import="client.model.*" %>

<%Requests req=(Requests)session.getAttribute("SHARES");
req.calPurchase();%>
<%--Requests.java is a model (MVC) which acts like a shopping cart
req.calPurchase() calculates the purchase amount--%>
<script language="javascript" >
function checkBal()
{
<%--req.getAmt() and req.getBal() return purchase amount and balance respectively--%>
var puramt = <%=req.getAmt()%>;
var balamt=<%=Integer.parseInt(req.getBal())%>;
if(balamt-puramt<500)
{
alert("Insufficient Balance");
return false;
}

}
</script>

<form method="POST"action="Checkout.do" onSubmit=" return checkBal()" >
<input type="submit" value="Checkout"><br><br>
<a href="Reqst.html">Place More Requests</a>
</form>

<form method="POST" action="Modify.jsp" >
<%--code to display requests--%>
<input type="submit" name="action" value="Modify" >
</form>



<form method="POST"action="Remove.jsp" >
<%--code to display requests--%>
<input type="submit" name="action" value="Remove Request">
</form>

</body>
</html>

cheers,
Poonam K.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You need to set the new amount value to request object after modification and before submitting the page to display.
 
Poonam Kadu
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In DisReq.jsp I'm using a shopping cart like object of class Requests.java which contains a method calPurchase() to calculate the purchase amount

<%Requests req=(Requests)session.getAttribute("SHARES");
req.calPurchase();%>
<%--Requests.java is a model (MVC) which acts like a shopping cart
req.calPurchase() calculates the purchase amount--%>

When SaveChanges.java forwards the httprequest to DisReq.jsp ,I think it will recalculate the values for script variables puramt,balamt instead of considering the old values

cheers ,
Poonam K.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Poonam Kadu:
<%Requests req=(Requests)session.getAttribute("SHARES");
req.calPurchase();%>
<%--Requests.java is a model (MVC) which acts like a shopping cart
req.calPurchase() calculates the purchase amount--%>



It doesn't qualify to be called MVC at all.
 
Poonam Kadu
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Requests.java class is not only used by DisReq.jsp but primarily used by other servlets .

So can you please explain me why Requests.java doesn't qualify to be a model of MVC structure.

cheers,
Poonam K.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As you said your request.calPurchase() method calculates the purchase amount, hence I would call it M of MVC. Calling your M from V is Model 1 not MVC. It should be called through your controller.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For this particular issue what you need is to set the new purchase amount accordingly after calculation.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic