famfamfam
famfamfam

Reputation: 536

Wrong when use PrintWriter to write new HTML

I used PrintWriter to do this code :

        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        try {
            /* TODO output your page here. You may use following sample code. */
            out.println("<html>");
            out.println("<head>");
            out.println("<title>Update Page</title>");
            out.println("</head>");

            out.println("<body>");
            out.println("<center>");
            out.println("<h1>Please choose ID</h1>");
            out.println("</center>");
            out.println("<table width='359' border='1' align='center'>");
            out.println("<tr>");
            out.println("<td width='103'>ID:</td>");
            out.println("<th width='246'>");
            out.println("<select name='ID' id='ID' style='width:170px;' >");
            out.println("<option></option>");
            out.println("</select>");
            out.println("</th>");
            out.println("</tr>");
            out.println("<tr>");
            out.println("<td>Name:</td>");
            out.println("<th><input type='text' name='Name' id='Name' style='width:170px;' /></th>");
            out.println("</tr>");
            out.println("<tr>");
            out.println("<td>Address:</td>");
            out.println("<th><input type='text' name='Address' id='Address' style='width:170px;'/></th>");
            out.println("</tr>");
            out.println("<td>Email:</td>");
            out.println("<th><input type='text' name='Email' id='Email' style='width:170px;'/></th>");
            out.println("</tr>");
            out.println("<tr>");
            out.println("<td>Phone Number:</td>");
            out.println("<th><input type='text' name='Phone' id='Phone' style='width:170px;'/></th>");
            out.println("</tr>");
            out.println("<tr>");
            out.println("<td></td>");
            //=================
            out.println("<td>");
            out.println("<div>");        
            out.println("<input type='submit' name='FillValue' value='Fill ID' style='float:left'/>");

            out.println("<form action='UpdateServlet' method='post'>");
            out.println("<input type='submid' name='Submid' value='Submit'  style='float:right'/>");
            out.println("</form>");
            out.println("</div>");
            out.println("</td>");
            out.println("</tr>");
            //==============
            out.println("</table>");
            out.println("</body>");
            out.println("</html>");
        } finally {
            out.close();
        }

But something wrong when I click to Submid button, the result is :

HTTP Status 404 - /DungDV01852_Lab1_2_3/UpdateServlet

type Status report

message /DungDV01852_Lab1_2_3/UpdateServlet

description The requested resource (/DungDV01852_Lab1_2_3/UpdateServlet) is not available. Apache Tomcat/6.0.29

I Have class updateServlet. Another : I have the HTML :

            <td>
                <div>
                    <form action="FillServlet" method="post">
       <input type="submit" name="FillValue" value="Fill ID" style="float:left"/>
                    </form>
    <input type="submit" name="Submid" id="Submid" value="Submit"style="float:right"/>
                </div>
            </td>

It Run exactly, but the same when I use PrintWriter to write a new HTML is Wrong. Please help me. Thanks everyone

Upvotes: 1

Views: 7869

Answers (1)

Stephen C
Stephen C

Reputation: 718916

The code in your question will not cause a 404 error. A 404 will happens either because your code explicitly sets a 404 response by calling response.sendError(...), or because the request never made it to your servlet in the first place. And the most likely cause of the latter is that your web.xml file is not configuring and mapping your servlet properly.

If you want more help, please add the entire web.xml file to the Question.

Upvotes: 1

Related Questions