【问题标题】:Cannot Deploy Servlet Application on Google App Engine无法在 Google App Engine 上部署 Servlet 应用程序
【发布时间】:2014-11-22 18:16:45
【问题描述】:

一开始我已经成功部署了它,但是运行它的时候有个问题是它找不到我的servlet文件来转发页面然后我意识到我忘记在web.xml文件中配置一个servlet因此我添加了servlet标签到 web.xml 文件,但是当我尝试再次部署它时,它会显示此消息

"错误:服务器错误 服务器遇到错误,无法完成您的请求。 请在 30 秒后重试。”

所以我尝试在 web.xml 文件中删除一个 servlet 标记,然后它可以作为第一次部署。 所以我认为问题是由 servlet 标签引起的,但我现在把它放回 web.xml 文件。我不知道该怎么办。请帮忙。

这是 web.xml 文件

<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
  <servlet>
    <servlet-name>Cal</servlet-name>
    <servlet-class>Calculator</servlet-class>

  </servlet>

</web-app>

这是我的小服务程序

package cal;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Calculator
 */
public class Calculator extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public Calculator() {
        super();
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        String num1 = request.getParameter("num1");
        String num2 = request.getParameter("num2");
       double n1 = Double.parseDouble(num1);
       double n2 = Double.parseDouble(num2);
       double result = 0;

       if(request.getParameter("add")!=null){
           result = n1 + n2;

           request.setAttribute("result1",""+result);
       }
       else if(request.getParameter("sub")!=null){
           result = n1 - n2;

           request.setAttribute("result1",""+result);
       }
       else if(request.getParameter("mul")!=null){
           result = n1 * n2;

           request.setAttribute("result1",""+result);
       }
       else{
           result = n1 / n2;
           request.setAttribute("result1",""+result);
       }
       request.getRequestDispatcher("result.jsp").forward(request,response);
       return;
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

}

这是 appengine-web.xml

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
  <application>componentreport57</application>
  <version>2</version>

  <!--
    Allows App Engine to send multiple requests to one instance in parallel:
  -->
  <threadsafe>true</threadsafe>

  <!-- Configure serving/caching of GWT files -->
  <static-files>
    <include path="**" />

    <!-- The following line requires App Engine 1.3.2 SDK -->
    <include path="**.nocache.*" expiration="0s" />

    <include path="**.cache.*" expiration="365d" />
    <exclude path="**.gwt.rpc" />
  </static-files>

  <!-- Configure java.util.logging -->
  <system-properties>
    <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/>
  </system-properties>

  <!--
    HTTP Sessions are disabled by default. To enable HTTP sessions specify:

      <sessions-enabled>true</sessions-enabled>

    It's possible to reduce request latency by configuring your application to
    asynchronously write HTTP session data to the datastore:

      <async-session-persistence enabled="true" />

    With this feature enabled, there is a very small chance your app will see
    stale session data. For details, see
    http://code.google.com/appengine/docs/java/config/appconfig.html#Enabling_Sessions
  -->

</appengine-web-app>

【问题讨论】:

    标签: jsp google-app-engine servlets web-deployment gae-eclipse-plugin


    【解决方案1】:

    尝试完成 Calculator 类的限定。例如,

    <servlet-class>cal.Calculator</servlet-class>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-04-22
      • 2019-05-18
      • 2014-03-30
      • 2012-02-11
      • 2023-03-06
      • 2019-08-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多