indexrk.jsp

    if(doc.data().disease=="" && (doc.data().test!="exit site" || doc.data().test!="exit" || doc.data().test!="Exit Site") ){


cell5=row.insertCell(6);
cell5.innerHTML="<form method='post' target='tabCalc' action='ImageCalc'><input type='hidden' name='test' id='test' value="+doc.data().test+"><input type='hidden' name='latestsample' id='latestsample' value="+doc.data().image.toString()+"> <input type='hidden' name='samid' id='samid"+rownum+"' value="+doc.id.toString()+"><input type='hidden' name='patpat' id='patpat"+rownum+"' value="+doc.data().Patient.toString()+"><input type='hidden' name='colorvol' id='colorvol"+rownum+"' value="+doc.data().colour.toString()+"> <input type='submit' onclick='act()' value='Calculate' class='btn editbtn' id='b"+rownum+"'> </form>";
cell5.style.width="100px";
row.style.background="#b7daa4";

                }


ImageCalc.java


        package com.example.servlet;

import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.ServletInputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URL;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@WebServlet(
        name = "ImageCalc",
        urlPatterns = "/ImageCalc"
)
public class ImageCalc extends HttpServlet{



    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
         String[] answer;
         String image = req.getParameter("latestsample");
         //String DocId=req.getParameter("dropDownDest");
         String sampleId=req.getParameter("samid");
         String colorvol=req.getParameter("colorvol");
         String type=req.getParameter("test");

            System.out.println("vgierfvbierfvieufbeuj   "+type);


        //req.setAttribute("name",DocId);
        if(type.equalsIgnoreCase("pdbag") ||type.equalsIgnoreCase("cloudy bag")) {
            Patients p=new Patients();
            try {
                p.patients(image.toString());
            } catch (SQLException | ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            req.setAttribute("hexval",p.gethexval());
            req.setAttribute("color"," ");
            req.setAttribute("disease",p.getinterpretation());
            req.setAttribute("id",sampleId);
             p.clearall();
        }
        else if(type.equalsIgnoreCase("volume")) {
            int voltype=Integer.valueOf(colorvol);
            Volume v=new Volume();
            String fvol="";
            try {
                fvol = Volume.vol(image.toString(),voltype);
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
             req.setAttribute("id",sampleId);
             req.setAttribute("color", colorvol);
             req.setAttribute("hexval","---");
                //req.setAttribute("color","not required");
                req.setAttribute("disease",fvol);
             //req.setAttribute("disease",p.getinterpretation());
        }
        else if(type.equals("Exit site")|| type.equals("exit")) {
            req.setAttribute("hexval","---");
            req.setAttribute("color","---");
            req.setAttribute("disease","---");
            req.setAttribute("id",sampleId);
     }



                    RequestDispatcher view = req.getRequestDispatcher("res.jsp");
        view.forward(req, resp);

     }
}


错误信息

HTTP Status 404 – Not Found
Type Status Report

Message /WebProject/ImageCalc

Description : The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.


我的想法:
该错误可能是由于路径引起的。由于Servlet位于WebProject / src / com / example / Imagecalc位置。但是我不知道如何设置正确的URL。

最佳答案

您的web.xml可能不正确。

正确的web.xml应该根据您的项目:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
  <servlet>
    <servlet-name>imageCalc</servlet-name>
    <servlet-class>com.example.servlet.ImageCalc</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>imageCalc</servlet-name>
    <url-pattern>/ImageCalc</url-pattern>
  </servlet-mapping>
</web-app>


尝试在浏览器上单击URL:http://localhost:8080/WebProject/ImageCalc-浏览器应基于GET / POST请求打开。

10-06 16:11