gpt4 book ai didi

tomcat - HTTP 状态 404 -/liangweb/TimeForm

转载 作者:行者123 更新时间:2023-11-28 23:31:58 25 4
gpt4 key购买 nike

我刚刚开始使用 tomcat 和 servlet。在运行一些 html 页面后,我试图运行这个 timeform。它给我页面。但是当我点击提交页面时,它给我这个错误而不是时间。请帮助我。

    import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.text.*;

public class TimeForm extends HttpServlet {
private static final String CONTENT_TYPE = "text/html";
private Locale[] allLocale = Locale.getAvailableLocales();
private String[] allTimeZone = TimeZone.getAvailableIDs();

/** Process the HTTP Get request */
public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<h3>Choose locale and time zone</h3>");
out.println("<form method=\"post\" action=" +
"/liangweb/TimeForm>");
out.println("Locale <select size=\"1\" name=\"locale\">");

// Fill in all locales
for (int i = 0; i < allLocale.length; i++) {
out.println("<option value=\"" + i +"\">" +
allLocale[i].getDisplayName() + "</option>");
}
out.println("</select>");

// Fill in all time zones
out.println("<p>Time Zone<select size=\"1\" name=\"timezone\">");
for (int i = 0; i < allTimeZone.length; i++) {
out.println("<option value=\"" + allTimeZone[i] +"\">" +
allTimeZone[i] + "</option>");
}
out.println("</select>");
out.println("<p><input type=\"submit\" value=\"Submit\" >");
out.println("<input type=\"reset\" value=\"Reset\"></p>");
out.println("</form>");
out.close(); // Close stream
}

/** Process the HTTP Post request */
public void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
int localeIndex = Integer.parseInt(
request.getParameter("locale"));
String timeZoneID = request.getParameter("timezone");
out.println("<head><title>Current Time</title></head>");
out.println("<body>");
Calendar calendar =
new GregorianCalendar(allLocale[localeIndex]);
TimeZone timeZone = TimeZone.getTimeZone(timeZoneID);
DateFormat dateFormat = DateFormat.getDateTimeInstance(
DateFormat.FULL, DateFormat.FULL, allLocale[localeIndex]);
dateFormat.setTimeZone(timeZone);
out.println("Current time is " +
dateFormat.format(calendar.getTime()) + "</p>");
out.println("</body></html>");
out.close(); // Close stream
}
}

然后我编译它没有错误 javac -cp .;d:\apache\lib\servlet-api.jar TimeForm.java这是我的 web.xml 文件。

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">



<servlet>
<servlet-name>servertime</servlet-name>
<servlet-class>TimeForm</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>servertime</servlet-name>
<url-pattern>/servertime</url-pattern>
</servlet-mapping>
</web-app>

点击提交后出错-

类型状态报告

留言/liangweb/TimeForm

描述请求的资源不可用。

最佳答案

form method=\"post\"action =\""+ "/cs532/servertime\"

这一定是有用的完美解决方案。

关于tomcat - HTTP 状态 404 -/liangweb/TimeForm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29312999/

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