Danh mục

Java Server Pages: A Code-Intensive Premium Reference- P11

Số trang: 10      Loại file: pdf      Dung lượng: 258.93 KB      Lượt xem: 10      Lượt tải: 0    
tailieu_vip

Xem trước 2 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Java Server Pages: A Code-Intensive Premium Reference- P11:Before you begin reading Pure JSP Java Server Pages, you might want to take a look at its basicstructure. This should help you outline your reading plan if you choose not to read the text from cover tocover. This introduction gives you an overview of what each chapter covers.
Nội dung trích xuất từ tài liệu:
Java Server Pages: A Code-Intensive Premium Reference- P11 out.clear(); String _jspx_qfStr = ; _jspx_qfStr = _jspx_qfStr + ?employee= + Joe; _jspx_qfStr = _jspx_qfStr + &title= + Senior Engineer; pageContext.forward(MCPHome.jsp + _jspx_qfStr); return; } // end // begin out.write( ); // end // begin [file=C:\UseForward.jsp;from=(24,10);to=(26,4)]}You can see that there is nothing really complicated about this code snippet. It simply decides which JSPto forward to, creates the query string, and calls the pageContext.forward() method with the name ofthe JSP and the query string.The action enables a JSP author to generate HTML that contains the appropriate client-browser–dependent constructs, for example, OBJECT or EMBED, that will result in the download of theJava plug-in and subsequent execution of the specified applet or JavaBeans component.The tag is replaced by either an or tag, as appropriate for therequesting user agent, and written to the output stream of the response object. The attributes of the action provide configuration data for the presentation of the element. The syntax of the action is as follows: Table 10.4 contains the attributes and their descriptions for the action.Table 10.4: The Attributes for the ActionAttribute Definitiontype This attribute represents the type of plug-in to include. An example of this would be an applet.code This attribute represents the name of the class that will be executed by the plug-in.codebase This attribute references the base or relative path of where the code attribute can be found.Note There are additional attributes associated with the standard action, but these attributes are beyond the scope of this example. You can find further information in the JSP 1.1 specification. - 101 -The attributes indicate the optional parameters that can be passed to the applet orJavaBeans component.For our example, we are going to use an applet that contains a TextArea object into which a user cantype some notes. It does nothing else. Listing 10.6 contains the source for our sample applet.Listing 10.6: Applet1.javaimport java.awt.*;import java.awt.event.*;import java.applet.*;import javax.swing.*;public class Applet1 extends JApplet { boolean isStandalone = false; TextArea textArea1 = new TextArea(); GridLayout gridLayout1 = new GridLayout(1,2); //Get a parameter value public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } //Construct the applet public Applet1() { } //Initialize the applet public void init() { try { - 102 - textArea1.setText(); this.setSize(new Dimension(400, 296)); this.getContentPane().setLayout(gridLayout1); this.getContentPane().add(textArea1, null); } catch(Exception e) { e.printStackTrace(); }}//Get Applet informationpublic String getAppletInfo() { return Applet Information;}//Get parameter infopublic String[][] getParameterInfo() { return null;}// static initializer for setting look & feelstatic { try { UIManager.setLookAndFeel( UIManager.getSystemLookAndFeelClassName()); - 103 - } catch (Exception e) {} }}The JSP source that includes Applet1 is in Listing 10.7.Listing 10.7: UseJSPPlugin.jsp The syntax for including an applet plug-in is very similar to including an applet directly in an HTML page.To see the results of this JSP, copy the compiled Applet1.class and dt.jar files to the/purejsp/TestApplet directory and copy the UseJSPPlugin.jsp file to the/purejsp directory. Now open your browser to the following URL:http://yourserver:8080/purejsp/UseJSPPlugin.jspYou will now see an image similar to Figure 10.3. - 104 -Figure 10.3: The output from UseJSPPlugin.jsp.SummaryIn this chapter, we covered the JSP standard actions. You should feel comfortable with how they areimplemented and how you can use them.In Chapter 11, we cover the scope differences when using JavaBeans in a JSP.Chapter 11: JSPs and JavaBean ScopeOverviewAs we discussed in Chapter 3, JavaBeans and JSP Concepts, the standard act ...

Tài liệu được xem nhiều: