HTTP 404错误正在为以下程序抛出

时间:2013-11-28 09:52:53

标签: servlets

问题是url有参数的双引号

form.html

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
    <h1 align=”center”>CML Module Selection Page</h1>
    <form method=”POST” action=”SelectCML.do”>
        Select CML Module 
        <p>
            Module: <select name=”module” size=”1”>

                <option value=”Academics”>Academics</option>
                <option value=”StudentRecords”>Student Records</option>
                <option value=”Purchasing”>Purchasing</option>
                <option value=”Inventory”>Inventory</option>
            </select> <br>
            <br>
        <center>
            <input type=”SUBMIT”>
        </center>
    </form>
</body>
</html>

CMLSelect.java

package com.example.model;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

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

public class CMLSelect extends HttpServlet
 {
    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException{

    String module = request.getParameter("module"); 
    CMLExpert cmlExpert = new CMLExpert();
    List list = cmlExpert.getBrands("module");

    response.setContentType("text/html");
    PrintWriter writer = response.getWriter();
    writer.println("CML Experts List <br>");
    Iterator it = list.iterator();

    while (it.hasNext()){
        writer.print("<hr> authors are : <br>" +it.next());

    }


    }

}

的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>DynamicWeb</display-name>
  <welcome-file-list>
    <welcome-file>form.html</welcome-file>  
  </welcome-file-list>

  <servlet>
  <servlet-name>servletIntName1</servlet-name>
  <servlet-class>com.example.model.CMLSelect</servlet-class>
  </servlet>

  <servlet-mapping>
  <servlet-name>servletIntName1</servlet-name>
  <url-pattern>/SelectCML.do</url-pattern>  
  </servlet-mapping>

  </web-app>

1 个答案:

答案 0 :(得分:0)

Change this 

    <form method=”POST” action=”SelectCML.do”>
to

    <form method=”POST” action=”/SelectCML.do”>