gpt4 book ai didi

java - Google App Engine - 错误 503_服务不可用

转载 作者:行者123 更新时间:2023-11-30 04:43:54 25 4
gpt4 key购买 nike

我正在编写一个简单的 gae web 应用程序,它应该通过表单向我发送一封电子邮件:

我已经编写了该 gae 代码:

index.html:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>A form</title>
</head>
<body>
<form action="/feedback" method="post">

<!-- Simple text field -->
<label for="name">Name </label>
<input type="text" name="name"/>
<br/>

<!-- Email -->
<label for="email">Email </label>
<input type="email" name="email"/>
<br/>


<!-- Textarea -->
<label for="description">Description </label>
<textarea name="description" cols="50" rows="5">Type your comment here</textarea>
<br/>


<input type="submit" name="submit" value="Send Request" action="/feedback"/>
</form>
</body>
</html>

web.xml

<servlet>
<servlet-name>FeedbackServlet</servlet-name>
<servlet-class>at.wunderapps.servlets.FeedbackServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FeedbackServlet</servlet-name>
<url-pattern>/feedback</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

servlet:

import java.io.IOException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@SuppressWarnings("serial")
public class FeedbackServlet extends HttpServlet {

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String name = req.getParameter("name");
String description = req.getParameter("description");
String email = req.getParameter("email");
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);

String msgBody = name + description + email + " :EMAIL";

try {
Message msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("apps@gmail.com",
"Es FUNKTIONIERT!!!"));
msg.addRecipient(Message.RecipientType.TO, new InternetAddress("my.mail@mail.com", "Your name"));
msg.setSubject("Bestellung");
msg.setText(msgBody);
Transport.send(msg);

} catch (Exception e) {
resp.setContentType("text/plain");
resp.getWriter().println("Something went wrong. Please try again.");
throw new RuntimeException(e);
}

resp.setContentType("text/plain");
resp.getWriter().println(
"Thanks you for your feedback. An Email has been send out.");
}
}

当我做本地主机时,我得到:

HTTP ERROR: 503

Problem accessing /. Reason:

SERVICE_UNAVAILABLE

我得到的异常(exception)是:

java.lang.ClassNotFoundException: at.wunderapps.servlets

CRITICAL: javax.servlet.ServletContext log: unavailable javax.servlet.UnavailableException: at.wunderapps.servlets

20.07.2012 13:13:46 com.google.apphosting.utils.jetty.JettyLogger warn WARNUNG: failed FeedbackServlet: java.lang.NullPointerException 20.07.2012 13:13:46 com.google.apphosting.utils.jetty.JettyLogger warn WARNUNG: Failed startup of context com.google.appengine.tools.development.DevAppEngineWebAppContext@495c998a{/,C:\Users\Desktop\mailservice\war} java.lang.NullPointerException

我猜问题可能是 inde.html 找不到我的 servlet。但为什么,因为 web.xml 似乎没问题?你能帮我吗?

PS:我在 Windows 7 上运行它。

最佳答案

<servlet-class>at.wunderapps.servlets.FeedbackServlet</servlet-class>  

如果这是 servlet 的完全限定名称,则 FeedbackServlet.java 文件的第一行应该是

package at.wunderapps.servlets;   

并且 FeedbackServlet.class 文件应位于

<yourWebAppRootFolder>/WEB-INF/classes/at/wunderapps/servlets/FeedbackServlet.class   

或者,如果您使用 Eclipse 作为 IDE,则只需将代码放入

<yourWebAppRootFolder>/src/at/wunderapps/servlets/FeedbackServlet.java

关于java - Google App Engine - 错误 503_服务不可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11580240/

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