File: f1_web_apps013.htm

package info (click to toggle)
libnb-platform18-java 12.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 729,624 kB
  • sloc: java: 5,058,967; xml: 574,432; php: 78,788; javascript: 29,039; ansic: 10,278; sh: 6,386; cpp: 4,612; jsp: 3,643; sql: 1,097; makefile: 540; objc: 288; perl: 277; haskell: 93
file content (163 lines) | stat: -rwxr-xr-x 7,768 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<!--

    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at

      http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.

-->
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr">
<head>
<title>web.xml Visual Editor: Resource References</title>
<link rel="stylesheet" href="ide.css" title="Oracle BLAFDoc" type="text/css"/>
</head>

<body>
<p><a id="dd_multiview_references_resRefsNode" name="dd_multiview_references_resRefsNode"></a></p>
<div id="NBCSH3865"><!-- infolevel="all" infotype="General" --><a id="sthref523" name="sthref523"></a>
<h1>web.xml Visual Editor: Resource References</h1>
<a name="BEGIN" id="BEGIN"></a>
<p>Use the Resource References section to add, remove, and view the web application's resource references. 
<object classid="java:org.netbeans.modules.javahelp.BrowserDisplayer">
<param name="content" value="http://www.oracle.com/pls/topic/lookup?ctx=nb8200&id=NBDAG1114">
<param name="text" value="<html><u>How?</u></html>">
<param name="textFontSize" value="medium">
<param name="textColor" value="blue">
</object>
</p>
<p>To access a data source, a JMS connection factory, a JavaMail session, or a URL link from a web application, you must declare a resource reference in the application's web application deployment descriptor. The resource reference specifies a JNDI name, the object type, and the kind of authentication used when the resource is accessed. To connect the resource reference to the resource, you must map the JNDI name of the former to the latter. This mapping is done in the server-specific deployment descriptor file, such as the <code dir="ltr">sun-web.xml</code> file for the Glassfish application server.</p>
<p>You use the resource reference in your code to extract the resource you need. For example, a resource reference defined in the <code dir="ltr">web.xml</code> file is used to extract data from a data source as shown in <a href="#CHDHFBIA">Example: Resource Reference</a></p>
<div id="NBCSH3866"><a id="CHDHFBIA" name="CHDHFBIA"></a>
<p>Example: Resource Reference</p>
<pre xml:space="preserve" dir="ltr">
public BookDBAO () throws Exception {
   try  {
      Context initCtx = new InitialContext();
      Context envCtx = (Context)
        initCtx.lookup("java:comp/env");
      DataSource ds = (DataSource) envCtx.lookup("jdbc/BookDB");
      con =  ds.getConnection();
     System.out.println("Created connection to database.");
   } catch (Exception ex) {
     System.out.println("Couldn't create connection." + 
       ex.getMessage());
   throw new 
       Exception("Couldn't open connection to database: "
       + ex.getMessage());
}
</pre>
<!-- -->
<p>To declare a resource reference, you must register it in the <code dir="ltr">web.xml</code> file. When you do this, you provide information needed by the server to use the resource reference.</p>
<p>In the Visual Editor, click <b>References</b> at the top of the editor to open the References section, then click the Resource References header to open the Resource References section. 
<object classid="java:org.netbeans.modules.javahelp.BrowserDisplayer">
<param name="content" value="http://www.oracle.com/pls/topic/lookup?ctx=nb8200&id=NBDAG1114">
<param name="text" value="<html><u>How?</u></html>">
<param name="textFontSize" value="medium">
<param name="textColor" value="blue">
</object>
</p>
<p>Click <b>Add</b> to define a resource reference element with the following properties:</p>

<table summary="User interface elements and descriptions" dir="ltr" border="1" width="100%" frame="hsides" rules="groups" cellpadding="3" cellspacing="0">
<col width="24%" />
<col width="*" />
<thead>
<tr align="left" valign="top">
<th align="left" valign="bottom" id="r1c1-t20">Element</th>
<th align="left" valign="bottom" id="r1c2-t20">Description</th>
</tr>
</thead>
<tbody>
<tr align="left" valign="top">
<td align="left" id="r2c1-t20" headers="r1c1-t20">
<p>Resource Name</p>
</td>
<td align="left" headers="r2c1-t20 r1c2-t20">Specifies the resource reference's name, such as <code dir="ltr">myDataSource</code>.</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r3c1-t20" headers="r1c1-t20">
<p>Resource Type</p>
</td>
<td align="left" headers="r3c1-t20 r1c2-t20">Specifies the variable's name for validation, such as <code dir="ltr">java.lang.String</code>.</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r4c1-t20" headers="r1c1-t20">
<p>Authentification</p>
</td>
<td align="left" headers="r4c1-t20 r1c2-t20">Specifies the source of the authentification credentials.</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r5c1-t20" headers="r1c1-t20">
<p>&nbsp;&nbsp;&nbsp;&nbsp;Application</p>
</td>
<td align="left" headers="r5c1-t20 r1c2-t20">Programmatic authentification, provided by the application.</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r6c1-t20" headers="r1c1-t20">
<p>&nbsp;&nbsp;&nbsp;&nbsp;Container</p>
</td>
<td align="left" headers="r6c1-t20 r1c2-t20">(Default) Provided by the caller who logged in to the server and created the component instance.</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r7c1-t20" headers="r1c1-t20">
<p>Sharing Scope</p>
</td>
<td align="left" headers="r7c1-t20 r1c2-t20">By default, connections to a resource manager are shareable across web components in an application that use the same resource in the same transaction context.</td>
</tr>
<tr align="left" valign="top">
<td align="left" id="r8c1-t20" headers="r1c1-t20">
<p>Description</p>
</td>
<td align="left" headers="r8c1-t20 r1c2-t20">Specifies a description, such as <code dir="ltr">Resource Reference for My Data Source</code>.</td>
</tr>
</tbody>
</table>
<br />
<!-- -->
<a id="NBCSH3874" name="NBCSH3874"></a>
<hr><p><b>Related Topics</b></p>
<p><i>Developing Applications with NetBeans IDE</i>, 
<object classid="java:org.netbeans.modules.javahelp.BrowserDisplayer">
<param name="content" value="http://www.oracle.com/pls/topic/lookup?ctx=nb8200&id=NBDAG2812">
<param name="text" value="<html><u>&quot;About Deployment Descriptors&quot;</u></html>">
<param name="textFontSize" value="medium">
<param name="textColor" value="blue">
</object>
</p>
<p><i>Developing Applications with NetBeans IDE</i>, 
<object classid="java:org.netbeans.modules.javahelp.BrowserDisplayer">
<param name="content" value="http://www.oracle.com/pls/topic/lookup?ctx=nb8200&id=NBDAG1111">
<param name="text" value="<html><u>&quot;Configuring a Web Application&quot;</u></html>">
<param name="textFontSize" value="medium">
<param name="textColor" value="blue">
</object>
</p>

<!-- -->
<!-- Start Footer -->


<table summary="" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td align="left" width="86%"><a href="legal_notice.htm">
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements; and to You under the Apache License, Version 2.0.</a>
</td>
</tr>
</table>
<!-- -->
</body>
</html>