Google App Engine - 错误503_Service不可用 [英] Google App Engine - Error 503_Service Unavailable

查看:195
本文介绍了Google App Engine - 错误503_Service不可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个简单的gae webapp,它应该从一个表单发给我一个电子邮件:



我已经编码了gae代码:



index.html:

 <!DOCTYPE html> 
< html>
< head>
< meta charset =utf-8>
< title>表单< / title>
< / head>
< body>
< form action =/ feedbackmethod =post>

<! - 简单文本字段 - >
< label for =name> Name< / label>
< input type =textname =name/>
< br />

<! - 电子邮件 - >
< label for =email>电子邮件< / label>
< input type =emailname =email/>
< br />


<! - Textarea - >
< label for =description>说明< / label>
< textarea name =descriptioncols =50rows =5>在此输入您的评论< / textarea>
< br />


< input type =submitname =submitvalue =发送请求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);
属性props = new Properties();
会话session = Session.getDefaultInstance(道具,null);

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

try {
消息msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(apps@gmail.com,
Es FUNKTIONIERT !!!));
msg.addRecipient(Message.RecipientType.TO,new InternetAddress(my.mail@mail.com,你的名字));
msg.setSubject(Bestellung);
msg.setText(msgBody);
Transport.send(msg);

} catch(Exception e){
resp.setContentType(text / plain);
resp.getWriter()。println(出现问题,请重试。);
抛出新的RuntimeException(e);
}

resp.setContentType(text / plain);
resp.getWriter()。println(
感谢您的反馈,电子邮件已发送出去。
}
}

当我在做localhost时,我得到:

  HTTP错误:503 

访问问题。原因:

SERVICE_UNAVAILABLE

,我得到的例外是:


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警告WARNUNG:失败FeedbackServlet:java.lang.NullPointerException
20.07.2012 13:13:46 com.google.apphosting.utils.jetty.JettyLogger警告WARNUNG:上下文启动失败
com .google.appengine.tools.development.DevAppEngineWebAppContext @ 495c998a {/,C:\Users\Desktop\mailservice\war}
java.lang.NullPointerException




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



PS:我在Windows 7上运行。

解决方案

 < servlet的类> at.wunderapps.servlets.FeedbackServlet< / servlet的类> 

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

  package at.wunderapps.servlets; 

而FeedbackServlet.class文件应在

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

或者如果您在IDE中使用Eclipse,那么只需将代码放在

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


I am coding a simple gae webapp that should send me an email from a form:

I have coded that gae code:

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.");
    }
}

When I am doing localhost i get:

HTTP ERROR: 503

Problem accessing /. Reason:

    SERVICE_UNAVAILABLE

and the exceptions I get are:

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

I guess the problem could be that the inde.html does not find my servlet. But why, cause the web.xml seems to be alright? Can you please help me?

PS.: I am running it on windows 7.

解决方案

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

If that is the fully qualified name of your servlet, then the first line of the FeedbackServlet.java file should be

package at.wunderapps.servlets;   

and the FeedbackServlet.class file should be at

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

Or if you are using Eclipse for your IDE, then just place your code in

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

这篇关于Google App Engine - 错误503_Service不可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆