使用NetWeaver开发Web模块

Prerequisite

The Window ® Open Perspective ® Other ® J2EE perspective is open.

Creating the Web Module Project

The Web resources are developed in a Web Project in the J2EE perspective.

...

       1.      Choose File ® New ® Project  from the main menu.

       2.      Choose Web ® Dynamic Web Project 2.5 on the New Project screen.

       3.      Choose Next to proceed to the Create a Dynamic Web 2.5 Project screen.

       4.      Enter ConverterWEB in the Project Name field.

       5.      To assign the Web project to the previously created Enterprise Application Project, check Add Project to an EAR and select ConverterEAR from the EAR Project Name field.

       6.      Choose Finish to create your Web’s project structure.

Creating a Web Client

The Web client in this tutorial is a JSP.

...

       1.      In the Project Explorer choose ConverterWEB ® WebContent.

       2.      From the context menu of WebContent choose New ® Other.

       3.      On the New screen choose Web ® JSP.

       4.      Choose Next.

       5.      Enter index.jsp in the File Name field.

       6.      Choose Finish.

       7.      Implement the JSP as follows:

<%@ page import="com.sap.tutorial.javaee.ConverterLocal,

java.math.*, javax.naming.*"%>

 

<%!

  private ConverterLocal converterBean = null;

  public void jspInit() {

    try {

     InitialContext ic = new InitialContext();

     converterBean = (ConverterLocal)

     ic.lookup("java:comp/env/Converter");

    } catch (Exception ex) {

       System.out.println("Couldn't create converter bean."+

       ex.getMessage());

    }

  }

 

 public void jspDestroy() {

  converterBean = null;

  }

 

%>

<html>

<head>

<title>Currency Converter</title>

</head>

 

<body>

<h1> Currency Converter</h1>

<hr>

<p>Enter an amount to convert:</p>

<form method="get">

<input type="text" name="amount" size="20">

<input type="submit" value="Submit">

</form>

<%

  String amount = request.getParameter("amount");

  if ( amount != null && amount.length() > 0 ) {

  BigDecimal value = new BigDecimal(amount);

  BigDecimal euroAmount = converterBean.dollarToEuro(value);

  %>

 

<p>

<%= amount %> USD are <%= euroAmount %> EUR

<br>

<%

  BigDecimal dollarAmount =

  converterBean.euroToDollar(value);

%>

<%= amount %> EUR are <%= dollarAmount %> USD

</p>

<%

  }

%>

</body>

</html>

       8.      Save the index.jsp file.

Editing the web.xml Deployment Descriptor

...

       1.      Expand the WEB-INF folder under WebContent.

       2.      Double-click on the web.xml file to open it for editing.

       3.      Add the following code in the XML source to define a local EJB reference to Converter bean:

<ejb-local-ref>

  <ejb-ref-name>Converter</ejb-ref-name>

  <ejb-ref-type>Session</ejb-ref-type>

    <local>com.sap.tutorial.javaee.ConverterLocal</local>

  </ejb-local-ref>

       4.      To save the file, choose File  ® Save from the main menu.

Configuring the Project References

Since your Web project uses resources from the ConverterEJB project, you have to set these references:

...

       1.      Select ConverterWEB in the Project Explorer.

       2.      From the context menu choose Properties.

       3.      On the Properties of ConverterWEB screen choose Java Build Path ® Projects.

       4.      Choose Add.

       5.      Select ConverterEJB.

       6.      Choose OK.

       7.      Choose Project References.

       8.      On the Setting Java Build Path screen that pops up, choose Apply.

       9.      Select the ConverterEAR and ConverterEJB projects.

   10.      Choose OK.

Result

You have successfully created the Web module of the Converter Application. 

转载于:https://www.cnblogs.com/myitworld/archive/2006/12/22/2214970.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值