Recent Notes

Displaying notes 1 - 10
Created by Dr. Xi on July 29, 2010 18:46:57    Last update: July 29, 2010 18:48:15
This is an example of using java.beans.XMLEncoder and java.beans.XMLDecoder to serialize/deserialize Java objects to XML. Java code TestXMLEncoder.java: import java.io.*; import java.beans.XMLEncoder; import java.beans.XMLDecoder; public class TestXMLEncoder { public static void main(String[] args) throws Exception { TestXMLEncoder t = new TestXMLEncoder(); t.testSimpleBean(); t.testCompositeBean(); t.testNoDefaultConstructor(); } private void testSimpleBean() throws Exception { System.out.println("Testing simple bean"); File simpleBeanXml = new File("simplebean.xml"); SimpleBean b = new SimpleBean(); b.setName("Java"); encodeObject(b, simpleBeanXml); SimpleBean b2 = (SimpleBean) decodeObject(simpleBeanXml); System.out.println("Retrieved: " + b2); System.out.println(); } private void testCompositeBean() throws Exception { System.out.println("Testing composite bean"); File compositeBeanXml = new File("compositebean.xml"); CompositeBean b = new CompositeBean(); SimpleBean s = new SimpleBean(); s.setName("Nested"); b.setS(s); encodeObject(b, compositeBeanXml); CompositeBean b2 = (CompositeBean) decodeObject(compositeBeanXml); System.out.println("Retrieved: " + b2); System.out.println(); } private void testNoDefaultConstructor() throws Exception { System.out.println("Testing noDefaultConstructor"); ...
Created by freyo on July 27, 2010 21:18:24
Use android list targets to find valid targets: C:\android-sdk-windows\tools>android list targets Available Android targets: id: 1 or "android-2" Name: Android 1.1 Type: Platform API level: 2 Revision: 1 Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-P id: 2 or "android-3" Name: Android 1.5 Type: Platform API level: 3 Revision: 4 Skins: HVGA (default), HVGA-L, HVGA-P, QVGA-L, QVGA-P id: 3 or "android-4" Name: Android 1.6 Type: Platform API level: 4 Revision: 3 Skins: HVGA (default), QVGA, WVGA800, WVGA854 id: 4 or "android-5" Name: Android 2.0 Type: Platform API level: 5 Revision: 1 Skins: HVGA (default), QVGA, WQVGA400, WQVGA432, WVGA800, WVGA854 id: 5 or "android-6" Name: Android 2.0.1 Type: Platform API level: 6 Revision: 1 Skins: HVGA (default), QVGA, WQVGA400, WQVGA432, WVGA800, WVGA854 id: 6 or "android-7" Name: ...
Created by Dr. Xi on July 27, 2010 20:49:12
<?xml version="1.0"?> <project name="Ant input task example" default="all" basedir="."> <target name="all" depends="doit,don't"/> <target name="doit" depends="user-input" if="confirmed"> <echo>Task performed</echo> </target> <target name="don't" depends="user-input" unless="confirmed"> <echo>Task NOT performed</echo> </target> <target name="user-input"> <input validargs="y,n" addproperty="user-response"> Do you really want to do this? </input> <condition property="confirmed"> <equals arg1="y" arg2="${user-response}"/> </condition> </target> </project>
Created by Fang on July 27, 2010 18:58:42
The tags <fmt:setLocale> <fmt:setLocale value="locale" [variant="variant"] [scope="{page|request|session|application}"] /> The <fmt:setLocale> action stores the locale specified by the value attribute in the javax.servlet.jsp.jstl.fmt.locale configuration variable in the scope given by the scope attribute. If value is of type java.util.Locale , variant is ignored. This tag should be used at the beginning of the page. Example: <fmt:setLocale value="en_US"/> <fmt:requestEncoding> <fmt:requestEncoding [value="charsetName"] /> The <fmt:requestEncoding> action may be used to set the request's character encoding, in order to be able to correctly decode request parameter values whose encoding is different from ISO-8859-1 . This action calls the setCharacterEncoding() method on the HttpServletRequest with the character encoding name specified in the value attribute. Test it These tags will be tested in later sections.
Created by Fang on July 27, 2010 16:42:08    Last update: July 27, 2010 18:23:27
Three key concepts are associated with internationalization (I18N): Locale: a locale is identified by a language code along with an optional country code. For example: en for English, en_US for US English, zh_CN for simplified Chinese. Resource Bundle: a resource bundle is a properties file localized for a specific locale. For example, messages_en.properties may be a resource bundle for English, messages_zh.properties may be a resource bundle for Chinese. Basename: a basename identifies the same set of messages represented by all related resource bundles. In the above example, the basename is messages . When a user request comes to a web application, the resource bundle is retrieved using the basename and the preferred locales . The preferred locale can be either application-based or browser-based . When ...
Created by Fang on July 26, 2010 19:18:28    Last update: July 26, 2010 19:30:02
The tags <c:import> The <c:import> tag imports the contents of a URL and expose that in one of three ways: Import contents from a URL and write it out to the page (url may be relative or absolute): <c:import url="theUrl" /> Import contents from a URL and save it to a scoped variable string named by the var attribute. Use the scope attribute to define the scope of the exported variable. <c:import url="theUrl" var="importTest" scope="session"/> Import a URL and expose to a Reader object named by the varReader attribute. The scope attribute does not apply. The varReader scoped variable can only be accessed within the body of <c:import> . <c:import url="theUrl" varReader="theReader"/> <c:url> The <c:url> tag constructs a URL and writes it out to the ...
Created by magnum on July 26, 2010 16:39:46
You can get the servlet referrer URL from the Referer header ( HttpServletRequest.getHeader() ): request.getHeader("referer"); Note that referer is misspelled .
Created by magnum on July 26, 2010 15:55:41    Last update: July 26, 2010 15:57:21
Given the URL: http://www.mydomain.com/myWebApp/theServlet/p1/p2/p3;sid=123?param=abc This would be the output of the various method calls on HttpServletRequest : String scheme = request.getScheme(); // http String serverName = request.getServerName(); // www.mydomain.com int portNumber = request.getServerPort(); // default 80 String contextPath = request.getContextPath(); // /myWebApp String servletPath = request.getServletPath(); // /theServlet String pathInfo = request.getPathInfo(); // /p1/p2/p3;sid=123 String queryString = request.getQueryString(); // param=abc boolean isSecure = request.isSecure(); // false, would be true if protocol is HTTPS
Created by magnum on July 26, 2010 15:41:36
The HttpServletRequest.getRequestURL() method returns the URL for the servlet request as a StringBuffer . public String getCurrentUrl(HttpServletRequest req, boolean withQueryString) { String reqUrl = req.getRequestURL().toString(); String queryString = req.getQueryString(); if (withQueryString && queryString != null) { reqUrl += "?"+queryString; } return reqUrl; }
Created by meiu on July 22, 2010 22:40:23    Last update: July 22, 2010 22:41:04
Base64 encoding replaces every 3-byte (24bit) sequence with a 4-byte sequence with 6 effective bits in each byte - therefore eliminating un-printable characters. The expansion ratio is 4:3.
Previous  1 2 3 4 5 6 7 8 9 10 Next