Download Reserved namespaces in J2EE

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project

Document related concepts
no text concepts found
Transcript
JNDI
Big picture
Reserved namespaces in J2EE
Prefix
java:comp/env
Description
Environment
variables
java:comp/env/ejb
EJB references
java:comp/env/jdbc
JDBC DataSource
reference
Declaration example
<env-entry>
<env-entry-name>myValue</env-entryname>>
<env-entry-value>10</env-entry-value>
<env-entry-type>java.lang.String</enventry-type>
</env-entry>
<ejb-ref>
<ejb-ref-name>ejb/EmplRecord</ejb-refname>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.wombat.empl.EmployeeRecordHo
me</home>
<remote>com.wombat.empl.EmployeeRecord<
/remote>
</ejb-ref>
Возвращаемый объект имеет тип
javax.sql.DataSource.
<resource-ref>
<res-ref-name>jdbc/EmployeeAppDB</res-refname>
<res-type>javax.sql.DataSource</res-type>
1
java:comp/env/jms
JMS connection
factories
java:comp/env/url
URL connection
factories
JavaMail API
connection
factories
java:comp/env/mail
<res-auth>Container</res-auth>
</resource-ref>
Возможные классы для возвращаемых
объектов:
 javax.jms.QueueConnectionFactory
 javax.jms.TopicConnectionFactory
 javax.jms.ConnectionFactory
java.net.URL
javax.mail.Session
<resource-ref>
<res-ref-name>mail/Session</res-ref-name>
<res-type>javax.mail.Session</res-type>
<res-auth>Container</res-auth>
</resource-ref>
javax.transaction.UserTransaction
java:comp/UserTransaction JTA transaction
context
java:comp/ORB
CORBA ORB
references
Code examples
JNDI call in scope of J2EE container:
Context initCtx = new InitialContext();
Context envCtx = (Context) initCtx.lookup("java:comp/env");
Session session = (Session) envCtx.lookup("mail/Session");
Custom factory:
Hashtable hash = new Hashtable();
hash.put(Context.INITIAL_CONTEXT_FACTORY,
"com.siberon.ws.config.jndi.ConfigContextFactory");
hash.put("config.input.stream", new FileInputStream("test.txt"));
hash.put("config.validate", "true");
Context context = new InitialContext(hash);
Struts
Struts servlet registration
<servlet>
<servlet-name>
interface
</servlet-name>
<servlet-class>
org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<!-- *.do mapping must be last mapping because Struts uses last matched mapping -->
2
<servlet-mapping>
<servlet-name>
interface
</servlet-name>
<url-pattern>
*.do
</url-pattern>
</servlet-mapping>
<!-- Struts Tag Library Descriptors -->
<taglib>
<taglib-uri>struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-bean.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-html.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-logic.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>struts-tiles.tld</taglib-uri>
<taglib-location>/WEB-INF/tld/struts-tiles.tld</taglib-location>
</taglib>
Configuration file example
Here's a simple Struts configuration (struts-config.xml) for a login workflow:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration
1.2//EN"
"http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean
name="logonForm"
type="app.LogonForm"/>
</form-beans>
<action-mappings>
<action
path="/Welcome"
forward="/pages/Welcome.jsp"/>
<action
path="/Logon"
forward="/pages/Logon.jsp"/>
<action
path="/LogonSubmit"
type="app.LogonAction"
name="logonForm"
scope="request"
validate="true"
input="/pages/Logon.jsp">
3
<forward
name="success"
path="/pages/Welcome.jsp"/>
<forward
name="failure"
path="/pages/Logon.jsp"/>
</action>
<action
path="/Logoff"
type="app.LogoffAction">
<forward
name="success"
path="/pages/Logoff.jsp"/>
</action>
</action-mappings>
<message-resources parameter="resources.application"/>
</struts-config>
4
Related documents