Tomcat HTTP status 404

Source: Internet
Author: User
Today, servlet is used, so Tomcat is used. ^ _ ^, but after a simple small example is written, the ghost error HTTP status 404 is suddenly reported after Tomcat is started. in fact, there are many causes for such errors as 404. Here I will only share some of my problems here.
First, I wrote a servlet with the following code:

Package com;

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;

/*
* Create Date: 02:36:44
*
* Author: chunwei Wang
*
* Version: V1.0
*
* Description: describes the modified function.
*
*
*/

Public class myservlet extends httpservlet {

@ Override
Protected void doget (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {
// Todo auto-generated method stub
Printwriter out = response. getwriter ();
Out. println ("Hello World ");
Response. setcontenttype ("text/html; charset = gb2312 ");
String name = request. getparameter ("name ");
String age = request. getparameter ("Age ");
String sex = request. getparameter ("sex ");
Out. Print (name );
Out. Print (AGE );
Out. Print (sex );
System. Out. println (name );
System. Out. println (AGE );
System. Out. println (sex );
}

@ Override
Protected void dopost (httpservletrequest arg0, httpservletresponse arg1) throws servletexception, ioexception {
// Todo auto-generated method stub
Doget (arg0, arg1 );
}

}
The form page code is as follows:
<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "gb2312" %>
<%
String Path = request. getcontextpath ();
String basepath = request. getscheme () + "://"
+ Request. getservername () + ":" + request. getserverport ()
+ Path + "/";
%>

<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Base href = "<% = basepath %>">

<Title> my JSP 'index. jsp 'starting page </title>
<Meta http-equiv = "Pragma" content = "no-Cache">
<Meta http-equiv = "cache-control" content = "no-Cache">
<Meta http-equiv = "expires" content = "0">
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "Description" content = "this is my page">
<! --
<LINK rel = "stylesheet" type = "text/CSS" href = "styles.css">
-->
</Head>

<Body>
<Form name = "myform" Action = "Test2" method = "Post">
<H2 align = "center">
User Information
</H2>
Name:
<Input type = "text" name = "name">
<Br>
Age:
<Input type = "text" name = "Age">
<Br>
Gender:
<Input type = "text" name = "sex">
<Br>
<Input type = "Submit" value = "Submit">
<Input type = "reset" value = "clear">
</Form>
</Body>
</Html>

The Web. xml file is configured as follows:
<? XML version = "1.0" encoding = "UTF-8"?>
<Web-app version = "2.4" xmlns = "http://java.sun.com/xml/ns/j2ee"
Xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
Xsi: schemalocation = "http://java.sun.com/xml/ns/j2ee
Http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd>
<Servlet>
<Servlet-Name> test </servlet-Name>
<Servlet-class> com. myservlet </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> test </servlet-Name>
<URL-pattern>/Test2 </url-pattern>
</Servlet-mapping>
</Web-app>
In fact, my problem mainly lies in <form name = "myform" Action = "Test2" method = "Post">, Because I added a/before Test2 of action /, so I reported that kind of ghost error. I remember that I used to add/When I used it. At that time, there was no such error, but this time it would not work. no matter how it works, this time it should be OK. also, I want to remind you that the formaction OF THE FORM seems to be added/when you use struts later /. if a similar error occurs, you can pay attention to it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.