JBUILDER9 WebLogic7 actual articles
JSP servlet articles
Author: Huang Kai E_mail: hk_sz@163.com
First JSP Servlet
First, start JBUILDER
1. Start JBuilder: Start / Program / Borland JBuilder 9 Enterprise Trial / Borland JBuilder 9 Enterprise Trial;
2. If the instant window appears, click Close to close (generally only when logging in).
Second, create a project
1. Select File / New Project in the menu bar to create a new project, the engineering wizard is started;
2. Enter MathSample after NAME;
3. Click Next;
4. Click Next to accept the default option;
5. Click Finish.
Third, set the Web Application
1. Select File / New ... in the menu bar, pop up the Object Gallery window;
2. Click on the web subpage;
3. Select Web Application and click OK to appear the Web Application window;
4. Enter MathSample after NAME;
5. Confirm that Directory is also MathSample;
6. Accept all the default options;
7. Click OK. Web Application Attributes and Web Application Directory creation success. In addition, the web.xml file is created under the MathSample / Deployment Descriptors directory in the engineering window. This web.xml file is the configuration file of the Web Application, which contains information about the Context Path, Servlets, and Classes. Whenever you add a Class to your Application, JBuilder will automatically update it.
Fourth, create a JSPS
JavaServer Pages are typically applied to the representation of J2EE. In this section we will create a JSP to display HTML Page and other component servlet communications with J2EE. The JSP file contains HTML and Java Scriptlets.
1. Select File / New ... in the menu bar, pop up the Object Gallery window;
2. Click on the web subpage;
3. Select JavaServer Page and click OK to appear JSP window;
4. Enter NumBerspage after NAME;
5. Generate Sample Bean is not selected;
6. Select Generate Error Page;
7. Click Next;
8. Confirm that generate submit form is selected;
9. Click Next;
10. Click Next;
11 Accept NumBerspage_ERROR.JSP, click Next;
12. Click Finish. JSP Pages you can already see in the panel on the right, you expand MathSample / root Directory in the engineering window You can see NumBerspage.jsp and NumBerspage_ERROR.JSP there.
13. Select the above NumBerspage subpage in the document window, modify the code:
will:
<% @ Page ErrorPage = "NumBerspage_ERROR.JSP"%>
Replace with:
<% @ page errorpage = "numberspage_error.jsp" import = "java.util.calendar"%>]
JBuilder Generated JSP
Replace with:
The time is <% = Calendar.getInstance (). GetTime ()%>
ENTER NUMBERS:
will
Form method = "post"
Replace with:
Form action = "controller" method = "post"
will:
Replace with:
First Number: Strong>
Second Number: strong>
14. Select File / Save All to save your changes in the menu bar.
V. Create servlets
Now let's create a simple servlet. Servlets is a special Java Classes for an Extend The Httpservlet API. It is very similar to CGI Scripts, but you will find it better. In this article, this Servlet Serves is called Controller. It collects JSP input and displayed in the browser in the form of HTML Page after calculation.
1. Select File / New ... in the menu bar, pop up the Object Gallery window;
2. Click on the web subpage;
3. Select the servlet and click OK to appear the servlet window;
4. Enter the controller after the class; this wizard will create a Class of CLASS named Controller in the MathSample package. Click Next;
5. Do not choose DOGET (), select dopost ();
6. If selected, you don't choose Generate SHTML, the default is not selected;
7. Click Next;
8. Click Next;
9.Step 4 of 5 Window Displays the details of this servlet in the web.xml file;
10. Click Finish, servlet code automatically generate.
11. Select the above Controller sub page of the document window to modify the code of the Dopost Method:
in
PrintWriter out = response.getwriter ();
Then add:
INT Num1 = Integer.Parseint (Request.getParameter ("NUM1"));
INT Num2 = Integer.Parseint (Request.getParameter ("NUM2"));
Int results = Num1 Num2;
will
Out.println ("
The servlet HAS Received A Post. This is the reply. p>"); replacement to:
Out.println ("
" Num1 " " Num2 "=" Result " P>");
12. Select Project / Rebuild "Controller.java" on the menu bar, or select Controller.java directly in the engineering window to select Rebuild to execute. If there is no compilation error, you will be able to see the information of Build success in the information window below DIE.
You can now run this Web Application now. If you can see the correct result, then it is done.
My article is the first Auro Forum (www.newer.com.cn/bbs) and programmers forum (www.9cbs.net), welcome to reprint, but please keep the author and the name of the revision, thank you.