
Use this procedure to create a JSP that invokes the CalcProxy JavaBean and acts as a front end to your application.
The JSP contains an input form where you can specify which type of operation you want the enterprise bean to perform, and the numbers that are calculated. The JSP sends the input to the enterprise bean, and then displays the result.
Creating the JSP
The wizard creates the JSP in the project folder CalculatorWeb/webContent and opens the JSP Editor automatically. This editor displays the default content in the Preview pane.
Adding Source Code
<jsp:useBean id="calc" scope="session" class="com.sap.examples.calculator.beans.CalcProxy"/>
<FORM METHOD="post" ACTION="Calculator.jsp"> <P>Select Operation:</P> <P><SELECT NAME="expression"> <OPTION VALUE=1>Multiply <OPTION VALUE=2>Divide <option VALUE=3>Add <option VALUE=4>Subtract </SELECT></P> <P>First number:</P> <P><INPUT NAME="firstnumber" size=10></P> <P>Second number:</P> <P><INPUT name="secondnumber" size=10></P> <P><INPUT TYPE="SUBMIT" NAME="Submit" VALUE="Calculate"></P> </FORM> <P> <HR HEIGHT="1px" WIDTH="80%" COLOR="#000000"> </P>
<% try { %>
<P>
<B><%="Result is " + calc.getResult(request.getParameter("firstnumber"), request.getParameter("secondnumber"), request.getParameter("expression"))%></B>
</P>
<% } catch (Exception ex) { %>
<%=ex.getMessage() %>
<% } %>
|
|
The front end of the Calculator application is ready. If you now choose the Preview tab in the JSP Editor, the following preview layout is displayed:
Next step:
In the next step you will create a Web archive .