gpt4 book ai didi

java - Apache Tomcat :Path Error

转载 作者:行者123 更新时间:2023-11-28 23:40:55 27 4
gpt4 key购买 nike

你好,我有 JSP 和 Web_Service.java.Web_Service.java 只是一个 java 类。它有一个由 JSP 调用的方法。JSP 文件有两个按钮和两个文本框。当我输入一个数字并单击按钮,调用 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 服务类,它在 package 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 提示“请求的资源不可用”?我该怎么做才能解决此错误?

最佳答案

网络服务调用不正确。您必须为表单的 action 属性设置一些页面。该页面可以进行网络服务调用。

我为您建议使用 JSON 的 Spring MVC 休息服务:http://www.javacodegeeks.com/2013/04/spring-mvc-easy-rest-based-json-services-with-responsebody.html

关于java - Apache Tomcat :Path Error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19766909/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com