STIW2024 / Main-Issues

2 stars 0 forks source link

Hello World 2 #2

Closed zhamri closed 7 years ago

zhamri commented 7 years ago

Write a program using Servlets to display the following output:

Hello World
STIW2024 Software Engineering
jairam0905 commented 7 years ago

1 2 helloworld2

jairam0905 commented 7 years ago

Reference. https://www.youtube.com/watch?v=HAg77OnM55Y

Nurzyra commented 7 years ago

1

2

3

4

5

Nurzyra commented 7 years ago

References: https://www.javatpoint.com/creating-servlet-in-netbeans-ide http://www.studytonight.com/servlet/creating-servlet-in-netbeans.php

ezzat787 commented 7 years ago

code: 1 2 4

output: image image

reference: https://www.ntu.edu.sg/home/ehchua/programming/java/JavaServlets.html https://www.javatpoint.com/creating-servlet-in-netbeans-ide

kzkit commented 7 years ago

HTML servlet1 XML servlet2 Servlet.java servlet3 Output servlet4 Output servlet5

Koksheng commented 7 years ago

servlet1

Koksheng commented 7 years ago

servlet2

Koksheng commented 7 years ago

servlet3

Aman748 commented 7 years ago

Code :

package Issue2;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Aman
 */
@WebServlet(name = "Issue2", urlPatterns = {"/Issue2"})
public class Issue2 extends HttpServlet {
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            /* TODO output your page here. You may use following sample code. */
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Issue2 Servlet</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<div>Hello World</div>");
            out.println("<div>STIW2024 Software Engineering</div>");
            out.println("</body>");
            out.println("</html>");
        }
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }

}

Output :

se-issue 2_output

thiviya commented 7 years ago

1 2 3 4 5

reference http://www.studytonight.com/servlet/creating-servlet-in-netbeans.php

nadiahnaz commented 7 years ago

servlet_myservlet servlet_index_html servlet_web_xml servlet_web_browser_01 servlet_web_browser_02

reference: http://www.studytonight.com/servlet/creating-servlet-in-netbeans.php

JohnWick27 commented 7 years ago

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
    <servlet>
        <servlet-name>hello1</servlet-name>
        <servlet-class>NewServlet1</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>hello1</servlet-name>
        <url-pattern>/hello1</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
  <welcome-file>newhtml1.html</welcome-file> 
  </welcome-file-list>
</web-app>

newhtml1.html

<html>
    <head>
        <title>Hello World!</title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        <h1>
        <div>Hello World</div>
        <div>STIW2024 Software Engineering</div></h1>
    </body>
</html>

NewServlet1.java

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author Azimjon Khamdamov
 */
public class NewServlet1 extends HttpServlet {

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

            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet NewServlet1</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Servlet NewServlet1 at " + request.getContextPath() + "</h1>");
            out.println("</body>");
            out.println("</html>");
        }
    }

}

servlet

Reference: http://www.studytonight.com/servlet/creating-servlet-in-netbeans.php

Lilinhong123 commented 7 years ago

`package com.runoob.test;

import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;

/**

}`

1 2

NgZhengYi commented 7 years ago

import java.io.IOException; import java.io.PrintWriter;

import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;

/**

}

image

ariffafif commented 7 years ago

package testing;

import java.io.IOException; import java.io.PrintWriter;

import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse;

/**

}

image

YangYifei666 commented 7 years ago
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet(urlPatterns = {"/HelloWorld2"})
public class HelloWorld2 extends HttpServlet {

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        try (PrintWriter out = response.getWriter()) {
            out.println("<!DOCTYPE html>");
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Servlet HelloWorld2</title>");            
            out.println("</head>");
            out.println("<body>");
            out.println("<h1>Hello World</h1>");
            out.println("<h1>STIW2024 Software Engineerin</h1>");
            out.println("</body>");
            out.println("</html>");
        }
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }

}

image

ChoyCheeWei commented 7 years ago

1 2 3 4 5 reference : http://www.studytonight.com/servlet/creating-servlet-in-netbeans.php

yaopeng96 commented 7 years ago

picture1 picture2 picture3

kopilim96 commented 7 years ago

image image

kopilim96 commented 7 years ago

image image

Reference :- https://www.youtube.com/watch?v=JGwWNGJdvx8

yeepheng96 commented 7 years ago

screenshot 2017-11-22 17 40 40 screenshot 2017-11-22 17 41 08 screenshot 2017-11-22 17 41 15 screenshot 2017-11-22 17 41 32 screenshot 2017-11-22 17 41 41

References: https://www.javatpoint.com/creating-servlet-in-netbeans-ide https://www.tutorialspoint.com/html/html_basic_tags.htm

LoiTongFong commented 7 years ago

hw1 hw2 hw3

References: https://www.youtube.com/watch?v=HAg77OnM55Y https://www.youtube.com/watch?v=KJhDGYWgzTc