JBuilder9.0+Weblogic7.0ʵսƪ֮JSP+SERVLETƪ

Àà±ð£ºJava µã»÷£º0 ÆÀÂÛ£º0 ÍƼö£º

JBuilder9+Weblogic7ʵսƪ

JSP + SERVLETƪ

                                                                             ×÷Õߣº»Æ ¿­         

E_mail£º[email protected]

   

µÚһƪ JSP + SERVLET

 

Ò»¡¢Æô¶¯JBuilder

1.Æô¶¯JBuilder£º ¿ªÊ¼/³ÌÐò/Borland JBuilder 9 Enterprise Trial/Borland JBuilder 9 Enterprise Trial£»

2.Èç¹û¼´Ê±´°¿Ú³öÏÖ£¬µã»÷Close¹Ø±Õ£¨Ò»°ãÖ»ÔÚµÚÒ»´ÎµÇ¼ʱ³öÏÖ£©¡£

 

¶þ¡¢´´½¨Ò»¸ö¹¤³Ì

1.Ôڲ˵¥À¸Ñ¡ÔñFile/New Project ... ´´½¨Ò»¸öй¤³Ì£¬¹¤³ÌÏòµ¼Æô¶¯£»

2.ÔÚNameºóÊäÈëMathSample£»

3.µã»÷Next£»

4.µã»÷Next½ÓÊÜĬÈÏÑ¡Ï

5.µã»÷Finish¡£

 

Èý¡¢ÉèÖà Web Application

1.Ôڲ˵¥À¸Ñ¡ÔñFile/New...£¬µ¯³öObject Gallery´°¿Ú£»

2.µã»÷Web×ÓÒ³£»

3.Ñ¡ÔñWeb ApplicationÈ»ºóµã»÷OK£¬³öÏÖWeb Application´°¿Ú£»

4.ÔÚNameºóÊäÈëMathSample£»

5.È·ÈÏDirectoryºóÒ²ÊÇMathSample£»

6.½ÓÊÜËùÓеÄĬÈÏÑ¡Ï

7.µã»÷OK¡£web application attributesºÍweb application directory´´½¨³É¹¦¡£ÁíÍ⣬web.xmlÎļþ±»´´½¨ÔÚ¹¤³Ì´°¿ÚÖеÄMathSample/Deployment descriptorsĿ¼Ï¡£Õâ¸öweb.xmlÎļþÊÇweb applicationµÄÅäÖÃÎļþ£¬Ëü°üº¬the context path¡¢servletsºÍclassesµÄÐÅÏ¢¡£Ã¿µ±ÄãÌí¼ÓÒ»¸öclassµ½ÄãµÄapplication£¬JBuilder½«×Ô¶¯¸üÐÂËü¡£

 

ËÄ¡¢´´½¨ JSPs

JavaServer PagesÒ»°ãÓ¦ÓÃÓÚJ2EEµÄ±íʾ²ã¡£ÔÚ±¾½ÚÎÒÃǽ«´´½¨Ò»¸öJSP£¬ÓÃÀ´ÏÔʾHTML pageÒÔ¼°ÓëJ2EEµÄÁíÍâÒ»¸ö×é¼þservletͨÐÅ¡£JSPÎļþ°üº¬HTMLºÍjava scriptlets¡£

1.Ôڲ˵¥À¸Ñ¡ÔñFile/New...£¬µ¯³öObject Gallery´°¿Ú£»

2.µã»÷Web×ÓÒ³£»

3.Ñ¡ÔñJavaServer PageÈ»ºóµã»÷OK£¬³öÏÖJSP´°¿Ú£»

4.ÔÚNameºóÊäÈëNumbersPage£»

5. Generate sample bean²»Ñ¡£»

6. Ñ¡ÖÐGenerate Error page£»

7.µã»÷Next£»

8.È·ÈÏGenerate submit form±»Ñ¡ÖУ»

9.µã»÷Next£»

10.ÔÙµã»÷Next£»

11½ÓÊÜNumbersPage_error.jsp£¬µã»÷Next£»

12.µã»÷Finish¡£ÔÚÓұߵÄÃæ°åÖÐÒѾ­¿ÉÒÔ¿´¼ûJSP pages£¬ÔÚ¹¤³Ì´°¿ÚÖÐÄãÕ¹¿ªMathSample/Root directory¿ÉÒÔ¿´¼ûNumbersPage.jspºÍNumbersPage_error.jspÔÚÄǶù¡£

13.Ñ¡ÖÐÎĵµ´°¿ÚµÄÉÏ·½NumbersPage×ÓÒ³£¬ÐÞ¸ÄÆäÖеĴúÂ룺

½«£º

<%@ page errorPage="NumbersPage_error.jsp"%>

Ì滻Ϊ£º

<%@ page errorPage="NumbersPage_error.jsp" import="java.util.Calendar"%>

½«£º

JBuilder Generated JSP

Ì滻Ϊ£º

The time is <%= Calendar.getInstance().getTime() %><br><br>

Enter numbers:

½«

form method="post"

Ì滻Ϊ£º

form action="controller" method="post"

½«£º

<br><br>

Ì滻Ϊ£º

<strong>First Number: <input type="text" name="num1" value=""></strong>

<br><br>

<strong>Second Number: <input type="text" name="num2" value=""></strong>

<br><br>

14.Ôڲ˵¥À¸Ñ¡ÔñFile/Save All±£´æÄãµÄÐ޸ġ£

 

Îå¡¢´´½¨ Servlets

ÏÖÔÚ£¬ÈÃÎÒÃÇÀ´´´½¨Ò»¸ö¼òµ¥µÄServlet¡£ServletsÊÇÒ»¸öextend the HTTPServlet APIµÄÌØÊâµÄjava classes¡£Ëü·Ç³£ÀàËÆÓÚCGI scripts£¬µ«ÊÇÄ㽫·¢ÏÖËü±íÏֵøü³öÉ«¡£ÔÚ±¾ÆªÖУ¬Õâ¸öservlet servesÃûΪcontroller¡£Ëü½«ÊÕ¼¯JSPµÄÊäÈë²¢ÔÚ¼ÆËãºóÒÔHTML pageµÄÐÎʽÏÔʾÔÚä¯ÀÀÆ÷ÖС£

1.Ôڲ˵¥À¸Ñ¡ÔñFile/New... £¬µ¯³öObject Gallery´°¿Ú£»

2.µã»÷Web×ÓÒ³£»

3.Ñ¡ÔñServletÈ»ºóµã»÷OK£¬³öÏÖServlet´°¿Ú£»

4.ÔÚClassºóÊäÈëController£»Õâ¸öÏòµ¼½«´´½¨Ò»¸öÔÚmathsample°üÖÐÃûΪControllerµÄclass¡£µã»÷Next£»

5.²»Ñ¡doGet()£¬Ñ¡ÖÐdoPost()£»

6.Èç¹ûÑ¡ÖеĻ°£¬²»Ñ¡Generate SHTML£¬Ä¬ÈÏÊDz»Ñ¡£»

7.µã»÷Next£»

8.µã»÷Next£»

9.Step 4 of 5´°¿ÚÏÔʾÕâ¸öservletÔÚweb.xmlÎļþÖеÄÏêϸÐÅÏ¢£»

10.µã»÷Finish£¬servlet code×Ô¶¯Éú³É¡£

11. Ñ¡ÖÐÎĵµ´°¿ÚµÄÉÏ·½Controller×ÓÒ³£¬ÐÞ¸ÄÆäÖÐdoPost methodµÄ´úÂ룺

ÔÚ

PrintWriter out = response.getWriter();

Ö®ºóÌí¼Ó£º

int num1 = Integer.parseInt(request.getParameter("num1"));

int num2 = Integer.parseInt(request.getParameter("num2"));

int result = num1 + num2;

½«

out.println("<p>The servlet has received a POST. This is the reply.</p>");

Ì滻Ϊ£º

out.println("<p>"+num1+" + "+num2+" = "+ result + "</p>");

12.Ôڲ˵¥À¸Ñ¡ÔñProject/Rebuild ¡°Controller.java¡±Ö´ÐУ¬Ò²¿ÉÒÔÖ±½ÓÔÚ¹¤³Ì´°¿ÚÖÐÑ¡ÖÐController.java°´ÓÒ¼üÑ¡ÖÐRebuildÀ´Ö´ÐС£Èç¹ûûÓбàÒë´íÎóµÄ»°£¬Ä㽫¿ÉÒÔÏÂDIEÏ·½µÄÐÅÏ¢´°¿ÚÖп´µ½Build SuccessfulµÄÐÅÏ¢¡£

µ½ÏÖÔÚÄãÒѾ­¿ÉÒÔÔËÐÐÕâ¸öweb applicationÁË¡£Èç¹ûÄãÄÜ¿´µ½ÕýÈ·µÄ½á¹û£¬ÄÇô¾ÍÍê³ÉÁË¡£

   

ÎÒµÄÎÄÕÂÊ×·¢Å£¶úÂÛ̳£¨www.newer.com.cn/bbs£©ºÍ³ÌÐòÔ±ÂÛ̳£¨www.csdn.net£©£¬»¶Ó­×ªÔØ£¬²»¹ý£¬Çë±£Áô×÷ÕßÒÔ¼°ÐÞ¶©ÕßµÄÃû×Ö£¬Ð»Ð»¡£

±¾ÎĵØÖ·£ºhttp://com.8s8s.com/it/it17287.htm