Simple Test on Tomcat
Create a helloworld directory under the examples directory
Tomcat 6.0/webapps/examples/helloworld
Create the test. jsp file.
HTTP: /localhost: 8103/examples/helloworld/test. jsp
Run.
Lesson 1
1. Add dynamic code
<% = New java. util. Date () %>
2. Applet
<APPLET code = "" width = "300" Height = "200"> </APPLET>
3.
Lesson 3
1. jsp is first compiled into servlet
2. servlet is a Java class that implements servlet interfaces and accepts requests and generates responses.
Requests can come from Java, web clients, and other servlets.
3. httpservlet accepts HTTP requests and generates HTTP responses.
The servlet class is not directly implemented, but the httpservlet class is extended.
4. How JSP converts to Servlet
The server is responsible for instantiating JSP/Servlet and using the new () method.
New is the Java method used to create a space in the object content.
Activate the init () method for initialization
Now, the system is ready to process client requests.
The service method can process its own transaction logic.
Or write doget () or dopost () for your transaction logic ()
When the destroy () method is activated on the server, the JSP/servlet is destroyed.
Garbage collection is started and the finalize () method is used to clear the memory.
5. jsp Conversion
JSP is converted to the appropriate servlet code, that is, a. Java file.
The server provides the option to save the. Java file.
Once converted to A. Java file, it is compiled into a bytecode file. Class
The bytecode is generated and returned to the client.
6. Basic Structure of httpservlet
Void Init ()
Void Service ()
Void doget ()
Void dopost ()
Init is used for initialization.
If the request is post or get, it overwrites Service ()
Otherwise, overwrite post or get
7. The init () parameter is the servletconfig object.
8. The service parameters are httpservletrequest and httpservletresponse objects.
9. jsp and equivalent Servlet
Package com. hour3;
Import java. Io .*;
Import javax. servlet .*;
Import javax. servlet. http .*;
Public class powersof2 extends httpserv
{
Public void Service (
Httpservletrequest request,
Httpservletresponse response)
Throws ioexception, servletexception
{
Response. setcontenttype ("text/html ");
Servletoutputstream out = response. getoutputstream ();
Out. Print ("<HTML> ");
Out. Print ("}
}