使用NetWeaver开发Web模块

简介: PrerequisiteThe Window ® Open Perspective ® Other ® J2EE perspective is open.

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. 

相关文章
|
5天前
|
云安全 人工智能 安全
AI被攻击怎么办?
阿里云提供 AI 全栈安全能力,其中对网络攻击的主动识别、智能阻断与快速响应构成其核心防线,依托原生安全防护为客户筑牢免疫屏障。
|
15天前
|
域名解析 人工智能
【实操攻略】手把手教学,免费领取.CN域名
即日起至2025年12月31日,购买万小智AI建站或云·企业官网,每单可免费领1个.CN域名首年!跟我了解领取攻略吧~
|
9天前
|
安全 Java Android开发
深度解析 Android 崩溃捕获原理及从崩溃到归因的闭环实践
崩溃堆栈全是 a.b.c?Native 错误查不到行号?本文详解 Android 崩溃采集全链路原理,教你如何把“天书”变“说明书”。RUM SDK 已支持一键接入。
589 212
|
4天前
|
编解码 Linux 数据安全/隐私保护
教程分享免费视频压缩软件,免费视频压缩,视频压缩免费,附压缩方法及学习教程
教程分享免费视频压缩软件,免费视频压缩,视频压缩免费,附压缩方法及学习教程
233 138
|
存储 人工智能 监控
从代码生成到自主决策:打造一个Coding驱动的“自我编程”Agent
本文介绍了一种基于LLM的“自我编程”Agent系统,通过代码驱动实现复杂逻辑。该Agent以Python为执行引擎,结合Py4j实现Java与Python交互,支持多工具调用、记忆分层与上下文工程,具备感知、认知、表达、自我评估等能力模块,目标是打造可进化的“1.5线”智能助手。
827 60
|
7天前
|
人工智能 移动开发 自然语言处理
2025最新HTML静态网页制作工具推荐:10款免费在线生成器小白也能5分钟上手
晓猛团队精选2025年10款真正免费、无需编程的在线HTML建站工具,涵盖AI生成、拖拽编辑、设计稿转代码等多种类型,均支持浏览器直接使用、快速出图与文件导出,特别适合零基础用户快速搭建个人网站、落地页或企业官网。
1194 157
|
6天前
|
存储 安全 固态存储
四款WIN PE工具,都可以实现U盘安装教程
Windows PE是基于NT内核的轻量系统,用于系统安装、分区管理及故障修复。本文推荐多款PE制作工具,支持U盘启动,兼容UEFI/Legacy模式,具备备份还原、驱动识别等功能,操作简便,适合新旧电脑维护使用。
500 109