【发布时间】:2015-03-17 16:24:29
【问题描述】:
public class MailHandlerServlet extends HttpServlet {
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try {
Properties props = new Properties();
Session session1 = Session.getDefaultInstance(props, null);
MimeMessage message = new MimeMessage(session1, req.getInputStream());
//Extract out the important fields from the Mime Message
String subject = message.getSubject();
String contentType = message.getContentType();
printParts(message);
//Parse out the Multiparts
//Perform business logic based on the email
}
catch (IOException | MessagingException ex) {
}
}
private static void printParts(Part p) throws IOException, MessagingException {
Object o = p.getContent();
if (o instanceof String) {
out.println("This is a String");
out.println((String)o);
}
else if (o instanceof Multipart) {
out.println("This is a Multipart");
Multipart mp = (Multipart)o;
int count = mp.getCount();
for (int i = 0; i < count; i++) {
printParts(mp.getBodyPart(i));
}
}
else if (o instanceof InputStream) {
out.println("This is just an input stream");
InputStream is = (InputStream)o;
int c;
while ((c = is.read()) != -1)
out.write(c);
}
}
}
上面的代码给了我一个这样的错误......“这个 URL 不支持 HTTP 方法 GET”请帮我修复它。我在 GAE 中部署它。我正在编写此代码来接收到我的appspot.com 的邮件。我也更新了我的 appengine-web.xml 和 web.xml。当我尝试运行该页面时,它向我显示此错误。
【问题讨论】:
-
你已经实现了
doPost,它是针对 POST 请求的。对于 GET 请求,您需要doGet方法
标签: google-app-engine servlets cloud