0

I'm doing my assignment from my Servlet teacher and I'm facing some unknown issues. We need to make a simple form (web version). It seems like my HTML file can't find my Servlet file. I've attached my codes below.

I can run my Servlet code, but when I run my HTML, it tells me "The origin server did not find a current representation for the target resource or is not willing to disclose that one exists."

How do I get my HTML to connect with my Servlet? I already put '< form action="./RegisterFormServlet" method="get">' in my HTML.

also, in the Servlet part, is it possible for Eclipse to generate the HTML code in the 'out.println' part ? Or do I need to type it manually? Thanks a lot!

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;

/**
 * Servlet implementation class RegisterFormServlet
 */
@WebServlet("/RegisterFormServlet")
public class RegisterFormServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
     *      response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8"); 

        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        String title = "報名表單確認";

        String param1 = request.getParameter("name");
        String param2 = request.getParameter("school");
        String param3 = request.getParameter("department");
        String param4 = request.getParameter("gender");
        String param5 = request.getParameter("vehicle");
//      String param6 = request.getParameter("param3");
//      String param7 = request.getParameter("param3");
        
        
        out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
                   "Transitional//EN\n" +
                   "<HTML>\n" +
                   "<HEAD><TITLE>" + title + "</TITLE></HEAD>\n" +
                   "<BODY BGCOLOR=\"#FDF5E6\">\n" +
                   "<H1 ALIGN=CENTER>" + title + "</H1>\n" +
                   "<UL>\n" +
                   "  <LI><B>param1</B>: "
                   + param1 + "\n" +
                   "  <LI><B>param2</B>: "
                   + param2 + "\n" +
                   "  <LI><B>param3</B>: "
                   + param3 + "\n" +
                   "  <LI><B>param4</B>: "
                   + param4 + "\n" +
                   "  <LI><B>param5</B>: "
                   + param5 + "\n" +
                   "</UL>\n" +
                   "</BODY></HTML>");   
    }

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

}

below is my HTML code:

enter image description here

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Elena Hu
  • 1
  • 1

1 Answers1

0

Move your html files to root WebContent, change in line 9 you form action removing "./" and try again

Igor Vinicius
  • 111
  • 1
  • 9