2012-07-18 149 views
0

我已編碼的代碼GAE:GoogleAppEngine錯誤403

的index.html 甲形式

<!-- 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"/> 
</form> 
</body> 
</html> 

的web.xml

<servlet> 
     <servlet-name>FeedbackServlet</servlet-name> 
     <servlet-class>at.wunderapps.servlets</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> 
</web-app> 

的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("[email protected]", 
        "Es FUNKTIONIERT!!!")); 
      msg.addRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]", "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錯誤403

問題訪問/。原因:

FORBIDDEN 

爲什麼?

PS:我在Windows上,因此容器使用默認/ 7

+0

什麼是你開

標籤? – MStodd 2012-07-18 18:40:43

+0

對不起,我忘了發佈完整的代碼,但它的存在! – maximus 2012-07-18 19:15:39

回答

1

你的HTML頁面沒有指定給servlet的路徑運行它。

使用

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