Anonymous
Почему я получаю код ответа 200 при отправке запроса от Postman на сервер Tomcat в моем проекте. но получить 404 в друго
Сообщение
Anonymous » 30 окт 2024, 16:06
проблема
Почему я получаю код ответа 200 при отправке запроса от Postman на сервер Tomcat в моем проекте. но получите 404 в другом проекте?
В мой проект HealthHelper
В мой проект HealthHelper,
Сначала я запустил сервер Tomcat.
Я отправил запрос со следующим URL-адресом и необработанными данными от Postman до Tomcat Server v9.0.
Я получаю запрос и обрабатываю его с помощью Java код с пакетом javax.servlet.
url
Код: Выделить всё
http://localhost:8080/HealthHelper/dietDiary/query/byTime
необработанные данные
Код: Выделить всё
{
"diaryId":2,
"userId":2,
"createDate":"2021-12-26",
"createTime":"00:00:00",
"totalFat":2.52,
"totalCarbon":2.3,
"totalProtein":2.1,
"totalFiber":2.1,
"totalSugar":1.2,
"totalSodium":1.1,
"totalCalories":1.21
}
вывод в консоли Eclipse
Затем я получаю ожидаемый вывод в консоли Eclipse.
Код: Выделить всё
Ready to deserialize.
dietDiary:DietDiary [diaryId=2, userId=2, createDate=2021-12-26, createTime=00:00:00, totalFat=2.52, totalCarbon=2.3, totalProtein=2.1, totalFiber=2.1, totalSugar=1.2, totalSodium=1.1, totalCalories=1.21]
Код
В моем проекте есть QueryDietDiaryByTimeController.java.
Код: Выделить всё
package web.dietdiary.controller;
import java.io.IOException;
import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.ArrayList;
import javax.naming.NamingException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject;
import web.dietdiary.constant.SqlDatePattern;
import web.dietdiary.service.impl.DietDiaryService;
import web.dietdiary.service.impl.DietDiaryServiceImpl;
import web.dietdiary.util.datetime.DateTimeHandler;
import web.dietdiary.util.datetime.DateTimeHandlerImpl;
import web.dietdiary.util.gson.GsonForSqlDateAndSqlTime;
import web.dietdiary.vo.DietDiary;
@WebServlet("/dietDiary/query/byDateAndTime")
public class QueryDietDiaryByTimeController extends HttpServlet {
private static final long serialVersionUID = 1L;
private DietDiaryService dietDiaryService;
@Override
public void init() throws ServletException {
try {
this.dietDiaryService = new DietDiaryServiceImpl(null);
} catch (NamingException e) {
e.printStackTrace();
}
}
@Override
protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException{
Gson gson = GsonForSqlDateAndSqlTime.gson;
JsonObject jsonObject = new JsonObject();
String errorMessage = "";
String result = "";
int affectedRow = 0;
ArrayList dietDiaries = new ArrayList();
DietDiary dietDiary = gson.fromJson(req.getReader(), DietDiary.class);
System.out.println("Ready to deserialize.");
System.out.println("dietDiary:"+dietDiary);
dietDiaries = this.dietDiaryService.search(dietDiary,3);
if(dietDiaries == null) {
errorMessage = "Unknown error!!!";
affectedRow = -1;
jsonObject.addProperty("result", false);
jsonObject.addProperty("affectedRow", affectedRow);
jsonObject.addProperty("errorMessage", errorMessage);
res.getWriter().write(jsonObject.toString());
return;
}
if(dietDiaries.isEmpty()){
errorMessage = "";
result = "not found.";
affectedRow = 0;
jsonObject.addProperty("result", result);
jsonObject.addProperty("affectedRow", affectedRow);
jsonObject.addProperty("errorMessage", errorMessage);
res.getWriter().write(jsonObject.toString());
return;
}
result = "";
result += "[";
result += "\n";
for(int i=0;iэти два кода одинаковы.
[*]можно успешно запустить сервер Tomcat v9.0.
[*]версия Tomcat Server и связанных с ним инструментов.
[*]Проверьте URL-адрес из (два отправленных выше запроса) верны.
[/list]
Я прочитал эти статьи.
[list]
[*]получает ошибку 404 при запросе на публикацию: почтальон
[/list]
Подробнее здесь: [url]https://stackoverflow.com/questions/79141173/why-do-i-get-the-response-code-200-when-request-sent-from-postman-to-tomcat-serv[/url]
1730293594
Anonymous
проблема[b]Почему я получаю код ответа 200 при отправке запроса от Postman на сервер Tomcat в моем проекте. но получите 404 в другом проекте? В мой проект HealthHelper В мой проект HealthHelper, [list] [*]Сначала я запустил сервер Tomcat. [*]Я отправил запрос со следующим URL-адресом и необработанными данными от Postman до Tomcat Server v9.0. [*]Я получаю запрос и обрабатываю его с помощью Java код с пакетом javax.servlet. [/list] url [code]http://localhost:8080/HealthHelper/dietDiary/query/byTime [/code] необработанные данные [code]{ "diaryId":2, "userId":2, "createDate":"2021-12-26", "createTime":"00:00:00", "totalFat":2.52, "totalCarbon":2.3, "totalProtein":2.1, "totalFiber":2.1, "totalSugar":1.2, "totalSodium":1.1, "totalCalories":1.21 } [/code] вывод в консоли Eclipse Затем я получаю ожидаемый вывод в консоли Eclipse. [code]Ready to deserialize. dietDiary:DietDiary [diaryId=2, userId=2, createDate=2021-12-26, createTime=00:00:00, totalFat=2.52, totalCarbon=2.3, totalProtein=2.1, totalFiber=2.1, totalSugar=1.2, totalSodium=1.1, totalCalories=1.21] [/code] Код В моем проекте есть QueryDietDiaryByTimeController.java. [code]package web.dietdiary.controller; import java.io.IOException; import java.sql.Date; import java.sql.Time; import java.sql.Timestamp; import java.util.ArrayList; import javax.naming.NamingException; import javax.servlet.ServletException; import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.JsonObject; import web.dietdiary.constant.SqlDatePattern; import web.dietdiary.service.impl.DietDiaryService; import web.dietdiary.service.impl.DietDiaryServiceImpl; import web.dietdiary.util.datetime.DateTimeHandler; import web.dietdiary.util.datetime.DateTimeHandlerImpl; import web.dietdiary.util.gson.GsonForSqlDateAndSqlTime; import web.dietdiary.vo.DietDiary; @WebServlet("/dietDiary/query/byDateAndTime") public class QueryDietDiaryByTimeController extends HttpServlet { private static final long serialVersionUID = 1L; private DietDiaryService dietDiaryService; @Override public void init() throws ServletException { try { this.dietDiaryService = new DietDiaryServiceImpl(null); } catch (NamingException e) { e.printStackTrace(); } } @Override protected void doGet(HttpServletRequest req,HttpServletResponse res) throws IOException{ Gson gson = GsonForSqlDateAndSqlTime.gson; JsonObject jsonObject = new JsonObject(); String errorMessage = ""; String result = ""; int affectedRow = 0; ArrayList dietDiaries = new ArrayList(); DietDiary dietDiary = gson.fromJson(req.getReader(), DietDiary.class); System.out.println("Ready to deserialize."); System.out.println("dietDiary:"+dietDiary); dietDiaries = this.dietDiaryService.search(dietDiary,3); if(dietDiaries == null) { errorMessage = "Unknown error!!!"; affectedRow = -1; jsonObject.addProperty("result", false); jsonObject.addProperty("affectedRow", affectedRow); jsonObject.addProperty("errorMessage", errorMessage); res.getWriter().write(jsonObject.toString()); return; } if(dietDiaries.isEmpty()){ errorMessage = ""; result = "not found."; affectedRow = 0; jsonObject.addProperty("result", result); jsonObject.addProperty("affectedRow", affectedRow); jsonObject.addProperty("errorMessage", errorMessage); res.getWriter().write(jsonObject.toString()); return; } result = ""; result += "["; result += "\n"; for(int i=0;iэти два кода одинаковы. [*]можно успешно запустить сервер Tomcat v9.0. [*]версия Tomcat Server и связанных с ним инструментов. [*]Проверьте URL-адрес из (два отправленных выше запроса) верны. [/list] Я прочитал эти статьи. [list] [*]получает ошибку 404 при запросе на публикацию: почтальон [/list] Подробнее здесь: [url]https://stackoverflow.com/questions/79141173/why-do-i-get-the-response-code-200-when-request-sent-from-postman-to-tomcat-serv[/url]