bonus.jsp

来自「J2EE编写企业应用教程(含源码)」· JSP 代码 · 共 84 行

JSP
84
字号
<%-- Comment    HTML code to start HTML page and body --%><HTML><HEAD><TITLE>Bonus Calculation</TITLE></HEAD>  <%--  Comment    Scriptlet for import statements    <%@ indicates a jsp directive --%>  <%@ page import="javax.naming.*" %>  <%@ page import="javax.rmi.PortableRemoteObject" %>  <%@ page import="Beans.*" %>  <%-- Comment    Scriptlet to get the parameters, convert string to     Integer to int for bonus calculation, and     declare/initialize bonus variable.    <% indicates a jsp scriptlet  --%>   <%! String strMult, socsec; %>  <%! Integer integerMult; %>  <%! int multiplier; %>  <%! double bonus; %><%  strMult = request.getParameter("MULTIPLIER");  socsec = request.getParameter("SOCSEC");  integerMult = new Integer(strMult);  multiplier = integerMult.intValue();  bonus = 100.00;%>  <%-- Comment    Scriptlet to look up session Bean --%><%  InitialContext ctx = new InitialContext();  Object objref = ctx.lookup("calcs");  CalcHome homecalc = (CalcHome)PortableRemoteObject.narrow(objref, CalcHome.class);%>  <%-- Comment    Scriptlet to create session Bean, call calcBonus    method, and retrieve a database record by the    social security number (primary key) --%><%  try {    Calc theCalculation = homecalc.create();    Bonus theBonus = theCalculation.calcBonus(multiplier, bonus, socsec);    Bonus record = theCalculation.getRecord(socsec);%>  <%-- Comment    HTML code to display retrieved data     on returned HTML page.  --%>    <H1>Bonus Calculation</H1>    Social security number retrieved: <%= record.getSocSec() %>    <P>    Bonus Amount retrieved: <%= record.getBonus() %>    <P>  <%-- Comment    Scriptlet to catch DuplicateKeyException --%><%  } catch (javax.ejb.DuplicateKeyException e) {    String message = e.getMessage();%>  <%-- Comment    HTML code to display original data passed to JSP    on returned HTML page --%>     Social security number passed in: <%= socsec %>    <P>    Multiplier passed in: <%= strMult %>    <P>    Error: <%= message %>  <%-- Comment    Scriptlet to close try and catch block --%><%  }%>  <%-- Comment    HTML code to close HTML body and page --%></BODY></HTML> 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?