JSP Getting Started Primary Tutorial Action

xiaoxiao2021-03-05  48

JSP Getting Started Primary Tutorial Action

JSP Actions Use you can dynamically insert a file, reuse the JavaBeans component, proceed to another page, or generate an HTML for the Java plugin. The action you can use is: (1) jsp: include - contains a file when the page is requested. (2) JSP: Usebean - find or instantiate a JavaBean. (3) JSP: setProperty - Set a JavaBeaN property. (4) JSP: getProperty - inserts the property of JavaBean into the output. (5) JSP: Forward - Let the requester can go forward to a new page. (6) JSP: Plugin - Generates a specific browser code with the Object or Embed tag to Java Plugins. 1, JSP: Include Action This action allows you to include some files on the upcoming page:

Unlike the include Directive, this action will contain the file when the page is requested, and include Directive is included when the JSP page is converted to servlet. In order to improve efficiency, include Action has a little sacrifice, ie, it does not allow the page included with a general JSP code (for example, it is not available to HTTP header), but it has significant flexibility, as JSP below Code, which implements four different fragments into the page below. Every time you change, you only need to modify these four files without changing the primary JSP page.

Whatsnew.jsp

JSP tutorial </ title> <body> <center> <table border = 5 bgcolor = "# EF8429> <tr> <tr> <Title"> what "s new at Chinese COMIC SITES </ TABLE> </ center> <p> Here is a summary of outness news stories: <ip> <li> <jsp: include page = "news / item1.html" flush = "true" / > <Li> <jsp: include page = "news / item2.html" flush = "true" /> <li> <jsp: include page = "news / item3.html" flush = "true" /> <li> <Jsp: include page = "news / item4.html" flush = "true" /> </ l> </ body> </ html> Of course, you can define yourself? Ml file, but if you pay attention:</p> <p>You should put your files within the news directory in your JSP directory.</p> <p>JSP: Use of UseBean Action</p> <p>First, grammar:</p> <p><Jsp: usebeanid = "beaninstancename" scope = "Page |" {class = "package.class" | type = "package.class" | class = "package.class" type = "package.class" "beanname =" {package.class | <% = expression%>} "type =" package.class "} {/> |> Other elements </ jsp: usebean>}</p> <p>This action allows you to load a JavaBean into a JSP page. This is a very useful ability because it allows you to use reusable Java classes without sacrificing performance. The simplest syntax is used to specify a bean:</p> <p><Jsp: usebean id = "name" class = "package.class" /></p> <p>This usually means "instantiate a class object by specifying a class and will be binded to a variable that is specified by the ID." However, just as we see, you can specify a scope property to make the bean not only contact the current page. In this case, it is very useful to get a reference to the existing bean, and only one new thing is created only when there is no the same ID and Scope beans. Now, you already have a bean, you can modify it via JSP: setProperty, or use the scriptlet or a clear call method by using the name specified by ID. When you say "this bean has a" X-type property called Foo "," You really means "this class has a method called getfoo, it returns a certain value of the X type, and another method is called Setfoo, it is parameter in x. "This JSP: setProperty action will introduce in detail in the next unit, but now you can give a clear value, give a property to indicate that this value is inherited from the parameter from the request. It is also possible to simplify the attribute to mark this value from inheritance from the parameter as the attribute name. You can get existing JSP expressions or scripTlet properties by calling applicable getxxx methods, or more common, using JSP: getProperty Action. Note that the class specified for the bean must be under the classpath of the server's rules, rather than reserved the path of the class that is automatically loaded when changing. For example, on the Java Web Server, it must go to the class directory or in a JAR file in the lib directory, instead of in the directory of servlets. Let us look at a very simple example that loads a bean and sets / get a simple string parameter. Beantest.jsp</p> <p><Head> <title> Reusing JavaBeans in jsp </ title> </ head> <body> <center> <Table Border = 5> <TR> <TH Class = "Title> Reusing JavaBeans in JSP </ Table> < / Center> <p> <jsp: usebean id = "test" class = "hall.simplebean" /> <jsp: setproperty name = "test" property = "message" value = "Hello WWW" /> <h1> message : <I> <jsp: getProperty name = "test" property = "message" /> </ i> </ h1> </ body></p> <p>SimpleBean.java</p> <p>The following is the original code of Bean:</p> <p>package hall; public class SimpleBean {private String message = "No message specified"; public String getMessage () {return (message);} public void setMessage (String message) {this.message = message;}} run results: page Output: Reusing JavaBeans in JSP</p> <p>Message: Hello WWW</p> <p>Second, JSP: Detailed usage of usebean</p> <p>The simplest way of using Bean is:</p> <p><Jsp: usebean id = "name" class = "package.class" /></p> <p>To load beans, you need to modify and retrieve the properties of the bean with JSP: SetProperty and JSP: getProperty. Moreover, there are two other options. First, you can use the format of the container, that is:</p> <p><JSP: Usebean ...> Body </ jsp: usebean></p> <p>It should be pointed out that the Body section should be performed only when Bean is instantiated, not when it is found and used each time. Beans can be shared, so not all JSP: Usebean statements produce a new bean instance. Second, in addition to ID or Class, there are three properties you can use: scope, type, and beanname. These properties summarize as follows:</p> <p>Attribute Meaning ID Names a variable, this variable will point to Bean. If there is a bean having the same ID and Scope, it is not new. Class pointed out the full package of Bean. Scope indicates that the Bean can be used before and after it. There are four possible values: Page, Request, Session, and Application. The default is Page, indicating that the bean is available only in current pages (saved in the current PageContext). A value of Request indicates that the bean is only for the current client request (saved in the servletRequest object). The value of the session pointed out that the object is available for all pages in the current HTTPSession life cycle. Finally, the value of Application pointers that the object can be used on all the shared servletsContext. Use JSP: UseBean creates a new bean only when there is no Same id and scope, if you already use it, and ignore the code that starts and ends with JSP: UseBean flag. TYPE indicates the type of variable that will point to the object. This must match the class name or a superclass or an interface implementation class. Remember, the name of the variable is specified by the id attribute. BeanName gives a name, you should be available in the instantiation method of Beans. It allows you to give Type and a beanName and omitted class properties.</p> <p>Third, JSP: SetProperty Action</p> <p>grammar:</p> <p><Jsp: setPropertyname = "beanInstanceName" {property = "*" | property = "propertyName" [param = "parameterName"] | property = "propertyName" value = "{string | <% = expression%>}"} /> In front of us, we know that you can use JSP: setProperty to assign a value for a bean attribute. You can use two ways to implement it. First, in JSP: UseBean (instead of) use JSP: SetProperty:</p> <p><Jsp: usebean id = "myname" ... />...<jsp:SetProperty name = "myname" property = "someproperty" ... /></p> <p>In this way, JSP: setProperty will be executed whether there is a bean having the same ID and Scope. Alternatively, JSP: setProperty appears within JSP: UseBean Elements, such as:</p> <p><JSP: Usebean ID = "MyName" ...> ... <jsp: setproperty name = "myname" property = "someproperty" ... /> </ jsp: usebean></p> <p>In this case, JSP: SetProperty is only performed when new objects are instantiated.</p> <p>The following is the available properties of four JSP: SetProperty:</p> <p>Attribute Usage Name This is a must-select attribute. It pointed out which bean's attribute will be set. JSP: Usebean must appear before JSP: setProperty. Property This is a must-select attribute. Indicates which property you will set. However, there is a special case: if it is worth "*", all names match the request parameters that match the properties of the bean will be passed to the corresponding attribute setting method. Value This is an optional attribute. It specifies the value of the properties set. The value of the string will be automatically converted to Numbers, Boolean, Boolean, Byte, Byte, Char, and Character by the standard Valueof method of the corresponding object or package. For example, the value of the Boolean or Boolean property will transform through the boolean.valueof method, and the value "42" of an int or Integer property will be converted via Integer.Valueof. You can't use the value and param properties at the same time, but both are allowed. PARAM This is an optional attribute. It indicates the parameters of the Request to be inherited. If the current Request does not have such a parameter, what does not do: the system does not pass NULL to the method of setting the properties. Therefore, you can use the default value of Beans. For example, the following program executes "Set the NumberOfItems property to any NumItems Request parameter, if there is such a request parameter, otherwise, nothing." <Jsp: setproperty name = "Orderbean" Property = "NumberofItems" PARAM = "NumItems" /> If you use Value and Param at the same time, this is the same as the property name that you set the name of the param to the bean. You can set the value of the Request corresponding to the properties of the value and param from "*" and omitted the value of Value and Param. In this case, the server matches the repeated lookup of the available properties and the request parameter to match the same name.</p> <p>Four, JSP: getProperty Action</p> <p>grammar:</p> <p><Jsp: getProperty name = "beaninstancename" property = "printyname" /></p> <p>This property retrieves the value of the property of the bean and convert it into a string, and then insert it into the output. It has two must-select properties: Name, with the name introduced by JSP: UseBean before, must be inserted attributes</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-36646.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="36646" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.066</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'KLVIToEa_2B7rHHDc2Fx2FEjpiiZXkbQilZgDOm1t_2B06BNNSm_2Bex4rA_2BIzB1Ox8U2LUFZ_2FB0sY_2B4wY6i04n4MJuA_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>