起初我已经成功部署了它但是在运行时有一个问题就是它找不到我的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>
这是我的servlet
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>
答案 0 :(得分:0)
尝试填写计算器类的资格。如,
<servlet-class>cal.Calculator</servlet-class>