One step to learn JSP (environment configuration, database connection, Web application configuration)

Source: Internet
Author: User
Tags odbc server port

First, JSP running environment configuration
1. (apache+ resin-2.0.5) configuration
If your site is based on Apache and now want to use JSP, how to do it. You can do this through some JSP engines that support Apache (such as Resin,tomcat,jser, etc.). Here's how to configure Apache+resin to make Apache support JSP. First, the installation of the configuration of Apache and resin each individual can operate normally.
The following installation paths for Apache and resin are as follows: C:apache and c:esin1.1.
2), configure Apache
This configures Apache so that it loads the resin JSP engine. Add the following command line to the c:apacheconfhttp.conf configuration file.
LoadModule Aucho_module
3), Configuration resin
Modify the Rsein configuration file (c:esinconf esin.conf) to specify the working directory of its JSP under Apache. Modified as follows:
<servlet-mapping rl-pattern= '/servlets/* ' servlet-name= ' invoker '/>
<servlet-mapping rl-pattern= ' *.xtp ' ervlet-name= ' Com.caucho.jsp.XtpServlet '/>
<servlet-mapping rl-pattern= ' *.jsp ' servlet-name= ' Com.caucho.jsp.JspServlet '/>
4) test
After completing the above steps, Apache has supported the JSP and servlet. Run Apache and start the resin JSP engine (run C:esin1.1insrun.exe).
The JSP's run directory is htdocs under Apache, while the servlet runs the directory as "C:apachehtdocsweb-infclass"
Put a JSP file (test.jsp) into the Apache Htdocs directory
Test.jsp is as follows:
<%@ page language=java?>
Browse http://localhost:port/test.jsp you will see: 2+2=4 this result. Note: Debug environment win98+apache_1_3_12+resin1.1, port is Web server port number

2. (IIS 5.0+ resin-2.0.5) configuration

The IIS Web is popular with many people for its simple management and support for ASPs. This article describes how to use resin to enable IIS to support JSPs and servlet.
1 respectively install the configuration IIS and resin2.0.5 so that each individual can operate normally. IIS and resin2.0.5 are followed by the following installation path: C:apache and c:esin2.0.5.
2) Configure IIS
1. Copy Iis_srun.dll to IIS scripts directory "C:inetpubscripts";
2. Create a configuration file (Resin.ini) in the c:inetpubscripts directory to specify the location of the resin configuration file.
Resin.ini contents are as follows: Cauchoconfigfile c:/resin2.0.5/conf/resin.conf
3) Configure resin
<servlet-mapping rl-pattern= '/servlets/* ' servlet-name= ' invoker '/>
<servlet-mapping rl-pattern= ' *.xtp ' ervlet-name= ' Com.caucho.jsp.XtpServlet '/>
<servlet-mapping rl-pattern= ' *.jsp ' servlet-name= ' Com.caucho.jsp.JspServlet '/>
4) test
1, run IIS, start resin JSP engine (run C:esin2.0.5insrun.exe)
2, put a JSP file (test.jsp) in the IIS C:inetpubwwwroot directory.
Test.jsp is as follows:
<%@ page language=java?>
2+2=<%=2+2%> Browse http://localhost:port/test.jsp. You will see: 2+2=4<?? This result note: Port is the port number, debugging environment nt4.0+iis+resin1.1

The learning of data connection pool
Poolman is an excellent connection pool. Download address for
A JDBC URL consists of three parts: the protocol identifier (always JDBC), the driver identification (such as ODBC, IDB, Oracle, and so on), and the database identity (its format is dependent on the driver). For example, Jdbc:odbc:demo is a JDBC URL that points to the demo database, and access to the database uses the JDBC-ODBC driver. Each connection pool has a name for use by the client program and an optional user account, password, maximum number of connections. If some of the database operations supported by a Web application can be performed by all users, while others should be performed by a specially licensed user, a connection pool can be defined for two types of operations, two connection pools use the same JDBC URL, but different accounts and passwords are used.

The study of naming class

Naming class
The Java.rmi.Naming class provides storage and access to remote objects in the remote object Registration service Program
The method of the reference. The methods in the naming class are in the form of the URL format java.lang.String

As one of the parameters:

Where host is registered service program hosts (remote or local), port is the registration service program
The port number that receives the call, name is a simple string that is not interpreted by the registry. Host and Port
is optional. If host is omitted, the host defaults to the local host. If the port is omitted,

The port defaults to 1099, that is, the RMI System Enrollment Service Program Rmiregistry "public
Zhou know "port.
The remote object binding name is the remote object associated with or registered name that is used later, and can be used to query the far
Process object. You can use the bind or Rebind method of the naming class to associate a remote object with a name

When a remote object has been registered (bound) with the RMI enrollment service on the local host, the calling program on the remote
(or local) host can query the remote object by name, obtain its reference, and then invoke the remote method on the
object. When necessary, a server running on a host can share a registration service
Each process of the server can also create and use its own registration service program
(for more information, see Java.rmi.registry.LocateRegistry.createRegistry method)

Package java.rmi;
Public final class naming
public static Remote lookup (String URL)
Throws Notboundexception,,
public static void bind (String url, Remote obj)
Throws Alreadyboundexception,,
public static void rebind (String url, Remote obj)
Throws RemoteException,;
public static void unbind (String URL)
Throws RemoteException, Notboundexception,
public static string[] list (String URL)
Throws RemoteException,;
The lookup method returns the remote object associated with the file part of the name. If the name is not bound to the object
, the notboundexception is thrown.
The bind method binds the specified name to the remote object. If the name is already bound to an object,

Throws the Alreadyboundexception.

The rebind method always binds the name to the object, regardless of whether the name is bound or not. The original binding will be lost.

The Unbind method cancels the binding between the name and the remote object. If there is no binding, the Notbound is thrown

The list method returns an array of String objects containing the binding URL in the registration service program
The snapshot.
In order to query the registration service program for its content list, only the host name and port information on the URL is required;
, the "file" portion of the URL is ignored.
Note: These methods may also throw java.rmi.AccessException. Accessexception table
Shows that the caller has no
Permissions for the line-specific operation. For example, only local clients on the host running the Registration service program allow
Perform bind, rebind
and unbind operations. However, the lookup operation can be invoked by any non-local client.

Web.xml's study

Now I've changed to Tomcat's running environment.
Web.xml specific syntax please see this URL

JSP gets the parameters defined in the Web.xml

To set the parameters in the Web.xml file:
<?xml version= "1.0" encoding= "Iso-8859-1"?>
<! DOCTYPE Web-app Public "-//sun Microsystems, INC.//DTD Web Application 2.3//en" "Http:// DTD ">

<servlet-name> myjsp </servlet-name>
<jsp-file>/myjsp.jsp </jsp-file>

<servlet-name> myjsp </servlet-name>
<url-pattern>/myurl/* </url-pattern>


The following program cannot take out the value of the parameter Firstparam defined in Web.xml firstparamvalue
My init parameter is <%= application.getinitparameter ("Firstparam")%>

The following program can take out the value of the parameter Firstparam defined in Web.xml firstparamvalue
String Str1;
Str1=config.getinitparameter ("Firstparam");
Out.println (STR1);

Because config is an object of class Javax.servlet.ServletConfig, application is an object of class Javax.servlet.ServletContext.
If you specify that the listening port for WebLogic server is 80, you do not need to enter the port in IE
Http://hostname/myfile.html replaces http://hostname:portnumber/myfile.html.
The study of Jndi

Jndi full name Java naming and Directory Interface
Jndi is a standard extension of the Java platform, providing a set of interfaces, classes, and concepts about namespaces. Like many other Java technologies, Jdni is a provider-based technology that exposes an API and a service supply interface (SPI). This means that any technology that is based on the name can provide services through Jndi, as long as Jndi supports this technology. The technologies currently supported by Jndi include LDAP, CORBA Common Object Service (COS) name Services, RMI, NDS, DNS, Windows registry, and so on. Many Java EE technologies, including EJBS, rely on Jndi to organize and locate entities.
Jdni the object and name by the concept of binding. In a file system, the filename is bound to a file. In DNS, an IP address binds a URL. In the directory service, an object name is bound to an object entity.
A set of bindings in Jndi are referenced as contexts. A set of actions exposed by each context is consistent. For example, each context provides a lookup operation that returns the corresponding object of the specified name. Each context provides the binding and removal of the binding name to an object's operation. Jndi exposes namespaces in a common way, using hierarchical contexts and child contexts that use the same naming syntax.
Use of Jndi:
1. You can use Jndi to get the properties of the object class.
such as: Attribute attr =directory.getattributes (personname). Get ("email");
string email = (string) attr.get ();
2. You can use Jndi to search for objects.
such as: Foxes = ("O=wiz,c=us", "Sn=fox", controls);
Find out whose name is Fox's employee in the Wiz department.
3. You can use Jndi to query objects like printers and databases through the Naming/directory service
such as: Query Printer
Printer Printer = (Printer) namespace.lookup (printername);
Printer.print (document);
4. You can use the Jndi list to show the specific level of the namespace
Such as:
Namingenumeration list = Namespace.list ("O=widget, c=us");
while (List.hasmore ()) {
Nameclasspair entry = (Nameclasspair) ();
Display (Entry.getname (), Entry.getclassname ());
The above is translated according to the Jndi document
In the Tomcat database connection pool configuration
JAVA:COMP/ENV represents the environment of your JVM, Comp=computer env=environment

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.