嗨,我有 JSP,而 Web_Service.java.Web_Service.java 只是一个 java 类。它有一个由 JSP 调用的方法。JSP 文件有一个两个按钮和两个文本框。当我输入一个数字并单击按钮时,ıt调用java类对数字做一些事情。
这是我的 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 说“请求的资源不可用”?我可以为这个错误做些什么?