无法在 Google App Engine 上部署 Servlet 应用程序



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

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

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

这是网络.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>

尝试对计算器类进行完全限定。 例如,

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

相关内容

  • 没有找到相关文章

最新更新