Pages

Showing posts with label web. Show all posts
Showing posts with label web. Show all posts

Thursday, 21 March 2013

Servlet: HTML filtering

I took this instance from "Core Servlets and JavaServer Pages" book by Marty Hall and Larry Brown.
This is my text book at the moment.
Here is some code:
The main problem is html-tags.. If you try to print out "a<b" (a less than b) - you will not see any text after < symbol. But the method filter() can replace "<" symbol with "&lt;"  (predefined letters combination):



/** <b - as a html tag:
     if (a<b) {
        doThis();
     } else {
        doThat();
     }
     */
    public static String filter(String input) {
        StringBuilder filtered = new StringBuilder(input.length());
        char c;
        for(int i=0; i<input.length(); i++) {
            c = input.charAt(i);
            if (c == '<') {
                filtered.append("&lt;");
            } else if (c == '>') {
                filtered.append("&gt;");
            } else if (c == '"') {
                filtered.append("&quot;");
            } else if (c == '&') {
                filtered.append("&amp;");
            } else {
                filtered.append(c);
            }
        }
        return(filtered.toString());
    } 

Thursday, 7 March 2013

Servlet. Reading All Request Parameters

Using request.getParameterNames() to get all parameter names.
Using request.getParameterValues(paramName) to get all (multiple) parameter values.

Enumeration paramNames = request.getParameterNames(); //All parameters
while(paramNames.hasMoreElements()) {
                String paramName = (String)paramNames.nextElement();
                String[] paramValues = request.getParameterValues(paramName); //All values
....
}

If the paramValues array has only one entry and contains only one empty string, then the parameter had no values. If the array has more than one entry, then the parameter had multiple values.










An empty String is returned if the parameter exists but has no value, and null is returned if there was no such parameter which name you asked.

Wednesday, 6 March 2013

Servlet. Race condition.


Somewhere in html:

form action="SynchTest" method="POST" name="form1"
input name="SubmitBtn" type="submit" value="SUBMIT"

_______________
public class SynchTest extends HttpServlet {
        Asynch a = new Asynch();

    protected void processRequest(HttpServletRequest request, 
                                  HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();

        try {
            String title = "SynchTest";
            int y = 40;
            if(a.getValue() > y) {
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException ex) {
                    out.print(ex.toString());
                }
                a.subtract(y);
            }
            String value = "Value is: " 
                            + String.valueOf(a.getValue()); 
            
            String threadInfo = Thread.currentThread().getName();
            value = value +"\n" + "Thread name is: " + threadInfo;
            out.println(MyHTML_util.getHTML(title,value));
        } finally {            
            out.close();
        }
    }
_____________________

Tuesday, 22 January 2013

Icons for web

In 2012 I am worked for one printing company in London. I have been in charge of preparation files for print. Every day I checked about 60 incoming files and fix about 10 of them. I was surprised how many incoming artworks didn't have any bleed (extra area for trimming).
And I had to create 2-3 absolutely new design a day. I love being busy. The more tasks - the better. 
When i had a little bit more spare time i created assets for company's website.
Before it looked like this. I have began from icons. First icons I have created in Illustrator. They were vector icons with gradient. I wanted to select colour for them later. I saved each icon separately as a png-file with transparency.
Then I had to create icons for every kind of our productions. In order it will be possible in future to replace previous icons to new ones i used their file names. It looked like a product_image211.png, a product_image312.png, a product_image789.png... and so on. In fact, I didn't have a direct access to webserver. I just saved web pages to my HD and I assume, all names of  icons were produced by webserver.

Our director who was responsible for updating of corporate website asked me to separate and to rename all files for each kind of our production separately. They asked me to make different size of icons for different sizes of our production (A3, A4, A5, A6, A7 - icons should be smaller depending of paper size). It was more than 250 icons.