-1

我正在编写一个使用 Apache Tomcat 求解 JSP 中的微分方程的网站。我写了一个 web 服务,jsp.jsp 有两个按钮调用 web 服务的功能。

这是我的 JSP 类 Web_Client.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form
action='http://localhost:8080/WebService/services/Web_Service/FahrenheitToCelsius'
method="post" target="_blank">
<table>
<tr>
<td>Fahrenheit to Celsius:</td>
<td><input type="text" size="30" name="Input"></td>
</tr>
<tr>
<td></td>
<td align="right"><input type="submit" value="Convert"></td>
</tr>
</table>
</form>

<form
action='http://localhost:8080/WebService/services/Web_Service/CelsiusToFahrenheit'
method="post" target="_blank">
<table>
<tr>
<td>Celsius to Fahrenheit:</td>
<td><input type="text" size="30" name="Input"></td>
</tr>
<tr>
<td></td>
<td align="right"><input type="submit" value="Convert"></td>
</tr>
</table>
</form>
</body>
</html>

以下代码是我的 web 服务类,它位于包 mypack:Web_Service.java: package mypacket;

/**
 * Web Service
 * Temp Converter
 *
 *@version 1.0 Release 1
 *@author mert
 *
 **/

public class Web_Service{
 public String FahrenheitToCelsius(String Input) {
 if (!Input.isEmpty() && isNumber(Input)) {
 double result = 0;
 result = Double.parseDouble(Input);
 result = (((result) - 32) / 9) * 5;
 Input = Double.toString(result);
 return Input;
 } else {
 return "ERROR! Please enter the input number...";
 }
 }

 public String CelsiusToFahrenheit(String Input) {
 if (!Input.isEmpty() && isNumber(Input)) {
 double result = 0;
 result = Double.parseDouble(Input);
 result = (((result) * 9) / 5) + 32;
 Input = Double.toString(result);
 return Input;
 } else {
 return "ERROR! Please enter the input number...";
 }
 }

以下代码是我的 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>Bitirme_Proje_New</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    <welcome-file>/axis2-web/index.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <display-name>Apache-Axis Servlet</display-name>
    <servlet-name>AxisServlet</servlet-name>
    <servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/servlet/AxisServlet</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>*.jws</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>AxisServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>
  <servlet>
    <display-name>Apache-Axis Admin Servlet Web Admin</display-name>
    <servlet-name>AxisAdminServlet</servlet-name>
    <servlet-class>org.apache.axis2.transport.http.AxisAdminServlet</servlet-class>
    <load-on-startup>100</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>AxisAdminServlet</servlet-name>
    <url-pattern>/axis2-admin/*</url-pattern>
  </servlet-mapping>
</web-app>

当我运行项目时,JSP 工作:出现按钮和文本框。但是当我在文本框中输入数字并单击按钮时,我收到此错误:

HTTP Status 404 - 
/WebService/services/Web_Service/FahrenheitToCelsius

type Status report

message /WebService/services/Web_Service/FahrenheitToCelsius

description The requested resource is not available.

Apache Tomcat/6.0.37

为什么 Apache Tomcat 说“请求的资源不可用”?我可以为这个错误做些什么?

4

1 回答 1

0

在 webapps 文件夹或 server.xml 中给出的 docBase 路径中,tomcat 找不到 webservice 的类文件。您可以再次编译 webservice 项目,也可以清理 apache tomcat 的工作文件夹,然后重试!

于 2016-03-11T12:27:52.703 回答