servlet 4 2 89 211 Web Content new
הקדמה ? servlet מהו התקנות דוגמת ריצה הטמעה 4 – תרגול 2 תכנות מתקדם 89 -211 יצירת דף האינטרנט כעת ניצור את דף האינטרנט שיבקש את השם המלא של המשתמש . Web. Content תחת new other… jsp נבחר index. jsp נקרא לקובץ כתבנית html נקבל קובץ <%@ page language="java" content. Type="text/html; . מוכנה charset=windows-1255" page. Encoding="windows-1255"%> <!DOCTYPE html PUBLIC "-//W 3 C//DTD HTML 4. 01 Transitional//EN" "http: //www. w 3. org/TR/html 4/loose. dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1255"> <title>Insert title here</title> </head> <body> </html> • •
הקדמה ? servlet מהו התקנות דוגמת ריצה הטמעה 4 – תרגול 2 תכנות מתקדם 89 -211 servlet יצירת ה package תחת ה Greeting. Servlet. java כעת נוצר לנו הקובץ . src המתאים ב package com. mycompany. servlet; לקובץ תבנית import java. io. IOException; import javax. servlet. Servlet. Exception; . מוכנה import javax. servlet. http. Http. Servlet; הרחבה של import javax. servlet. http. Http. Servlet. Request; import javax. servlet. http. Http. Servlet. Response; Http. Servlet public class Greeting. Servlet extends Http. Servlet { טיפול בשיטת private static final long serial. Version. UID = 1 L; public Greeting. Servlet() { ובשיטת get super(); . post } protected void do. Get(Http. Servlet. Request request, Http. Servlet. Response response) throws Servlet. Exception, IOException { } protected void do. Post(Http. Servlet. Request request, Http. Servlet. Response response) throws Servlet. Exception, IOException { } } • •
הקדמה ? servlet מהו התקנות דוגמת ריצה הטמעה 4 – תרגול 2 תכנות מתקדם 89 -211 servlet יצירת ה אליו נכתוב את התוצאה output stream נקבל את ה response ע"י . נוכל לגשת לפרמטרים השונים כפי שהוגדרו בטופס request ע"י לבצע כל חישוב שנרצה ולהחזיר תוצאה , נוכל לשמור מה שנרצה כאילו היינו כותבים . לתוך קובץ tomcat אלא ש אחראי להעביר את התוצאה חזרה אל המשתמש דרך . הדפדפן • • • protected void do. Post(Http. Servlet. Request request, Http. Servlet. Response response) throws Servlet. Exception, IOException { response. set. Content. Type("text/html; charset=UTF-8"); Print. Writer out = response. get. Writer(); String first. Name = request. get. Parameter("first. Name"). to. String(); String last. Name = request. get. Parameter("last. Name"). to. String(); out. println("<html>"); out. println("<head>"); out. println("<title>Servlet Greeting. Servlet</title>"); out. println("</head>"); out. println("<body>"); out. println("<p>Welcome " + first. Name + " " + last. Name + "</p>"); out. println("</body>"); out. println("</html>"); out. close(); } •
- Slides: 18