Java Servlet Example 1

Write a servlet to display a table that shows ODD numbers and EVEN numbers from number 1 to 10, as shown in the figure below. 

Screen Shot 2018 03 09 at 4.02.12 PM - Java Servlet Example 1

 

  • EvenOddServlet.java (put it in the “src” folder) 

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class EvenOddServlet extends HttpServlet {
    public void doGet(HttpServletRequest req, HttpServletResponse res) throws 
ServletException, IOException {
        res.setContentType("text/html");
        PrintWriter pw = res.getWriter();
        // Send the message
        pw.println("<table border='1'>");
        pw.println("<tr>");
        pw.println("<th style='background-color:red;'> Even </th>");
        for (int i = 1; i <= 10; ++i) {
            if (i % 2 == 0) {
                pw.println("<td>" + i + "</td>");
            }
        }
        pw.println("</tr>");
        pw.println("<tr>");
        pw.println("<th style='background-color:red;'> Odd </th>");
        for (int i = 1; i <= 10; ++i) {
            if (i % 2 != 0) {
                pw.println("<td>" + i + "</td>");
            }
        }
        pw.println("</tr>");
        pw.println("<table>");
    }
}

  • index.jsp (put it in the “web” folder) 

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title></title>
  </head>
  <body>

  </body>
</html>

  • web.xml (put it in the “WEB-INF” folder which resides inside the “web”) 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
    <display-name>myweb</display-name>

    <!-- Servlet Definitions  -->
   <servlet>
      <servlet-name>EvenOddServlet</servlet-name>
      <servlet-class>EvenOddServlet</servlet-class>
   </servlet>
<!--   Servlet Mappings   -->
   <servlet-mapping>
      <servlet-name>EvenOddServlet</servlet-name>
       <url-pattern>/EvenOddServlet</url-pattern>
   </servlet-mapping>
 </web-app>

 Note: To run this go to your browser and type: localhost:8080/EvenOddServlet

If you don’t know how to set up a servlet project in NetBeans, you may use this video as a reference:

 

java servlet

What the fuck is a java servlet?

 

Remember Java’s write once, run anywhere bullshit? Run anywhere…  Yeah, well Java programs can run on anything that has JVM. A toaster with JVM can run Java. An iPhone without it cannot. TAKE THAT JAVA! Well, it hasn’t stopped java developers to develop apps on iPhone using Java though. You see, this magical JVM thingy works and is fast enough because it is written in C/C++ for that specific OS. But the fucking pointers suck the life out of you so let’s stick to Java for now. 

 

WHAT THE FUCK IS A JAVA SERVLET THEN? 

As you’ve noticed I’ve just beat around the bush and haven’t still answered what the fuck Java Servlet is till now. Well, what if you wanted to leave the comfort of your desktop and mobile phone and wanted to develop apps for the good OL‘ web. Could you still do that? Now, what fun is it … if a language claims to run everywhere and can’t even run on the web. That would suck, right? 

Well for all the Java evangelists, the good news is that Java comes with full-fledged Servlet API which lets you build web apps without much hassle, unlike non-standard CGI thingy that Java used to have which we are not going to talk about because fuck it. 

 

WHAT? HOW THE HELL, DOES IT DO THAT? 

Think of a Servlet as a Java program or a Java class that is executed within the scope of Servlet containers (or web containers). You must be thinking, hold on their chief? What the fuck is a Web container now? Shit like Tomcat, Jetty etc. allow handling client requests and server responses and they are Web containers. 

Servlets use GET and POST request thingies to be able to snatch data from users. They can handle session and cookies thingies. They can process the motherfucking data and output the data in both text and binary formats such as XML, HTML, pdf, gif etc. They may use a thingy called JSP in many cases which we’ll talk about some other time. 

 

 

dp - How to change your facebook profile picture?

How to change your facebook profile picture?

Clickbait. Gotcha!  😉 

 Well, since you’re already here. I’ve got this shitty excuse for a list with random mumbo-jumbo that your brain is not even going to register. If these tips offend you, maybe you should not have watched too many Disney movies when you were younger. That being said, let us begin the list, mate.

   1) Make sure that you are not ugly 

photo 1495741770155 e4137dcb83ec?dpr=1&auto=format&fit=crop&w=1352&h=&q=60&cs=tinysrgb&crop= - How to change your facebook profile picture?

Aite.. I know. You already are and it’s not your fault. It’s your parents but… The latter

steps help you just tackle that so don’t worry. I have no clue how lists work now.

Thanks to you. 


 2) Get those harry potter magic wands ready

photo 1453761816053 ed5ba727b5b7?dpr=1&auto=format&fit=crop&w=1332&h=&q=60&cs=tinysrgb&crop= - How to change your facebook profile picture?

And I do understand that if you are a guy and straight this option is pretty much out of the question

unless you’re gay or good at stealing your girlfriend’s makeup. But still, our third entry comes to the rescue. 


 3) Call your metrosexual closeted bisexual photographer friend (monkey with a DSLR) 

photo 1498830923224 e1c12d1564a6?dpr=1&auto=format&fit=crop&w=1350&h=&q=60&cs=tinysrgb&crop= - How to change your facebook profile picture?

If you can’t afford him or find him around, you can try that iPhone fag instead.. shit

has okay-ish

camera, I guess. 


 4) Apply them filters 

photo 1500912644938 2fcd28844358?dpr=1&auto=format&fit=crop&w=1350&h=&q=60&cs=tinysrgb&crop= - How to change your facebook profile picture?

Get it? Filters? Get it? Get it? No? Die then. 


   5) Choose a caption (the more it doesn’t make sense, the better )

photo 1494236656430 f512d687ca18?dpr=1&auto=format&fit=crop&w=706&h=&q=60&cs=tinysrgb&crop= - How to change your facebook profile picture?


 6) Upload the shit and wait for the likes to blow up (must ignore anyone who comments for a while to appear more scarce)

photo 1492106087820 71f1a00d2b11?dpr=1&auto=format&fit=crop&w=668&h=&q=60&cs=tinysrgb&crop= - How to change your facebook profile picture?


 Conditional Step 7) Chances are you are way too hideous to be seen in public, in that case, try something creative. 

photo 1493124071986 cccebebe4cc3?dpr=1&auto=format&fit=crop&w=1510&h=&q=60&cs=tinysrgb&crop= - How to change your facebook profile picture?

You can choose to confuse people with creative props or angles or you may take photos in a group or at an angle where it is less obvious that you are hideous. 

 

Note: This article is not a satire and is to be taken seriously. You may choose to get offended by it. 

austin chan 275638 - ....

….

Aite.. it’s 4..30ish am … Mon 3:59 .. October 16.. 

Also I do admit that.. that featured photo .. has nothing whatsoever.. to do with the post ..

But hear me out, I’s got’s something really substantial to say…

most probably not though 

Yeah, I know. The fuck does it even matter? … Need to reach the hospital at  like 8… am..  and here I don’t fucking feel like sleeping because I want to read this shiny JS book. 

On a side note,  JS sucks. And it’s not even that serious of a programming language. Fuck my life. The day I thought …  And I do understand why these fags who need to feel important with their intellectual masturbation pretend that it’s any fun with their vims and C’s. Nobody gives a shit about them. They have to do something to kill their time and feel important .. I understand…

 But meh… Do something else with your life. Like, be that faggot with the camera.. the DLSR thingy.. DSLR I mean.. the fuck I care what it’s called? Why is it even named that? 

Don’t answer though. Forgot to bring the care.  

Like it’s fucking way more rewarding. You’ll have way more friends that way… Everybody likes that sophisticated looking faggot with long hair who might someday take pretty pictures of them and apply fuck ton of filter so that you look like fucking Brad Pitt… Megan Foxx or something… 

And don’t let the bullshit about a huge paycheck fool you. You can earn just as much shoving elephant shit… with much more fulfilling work life …

The fuck am I talking about? I need to sleep or read… or something.. but fuck you.. need to go 

 

But hey here’s a picture of a dog wrapped in a blanket thingy just so you feel like that you didn’t waste your time matthew henry 20172 - ....

Fuck you…