At first I have successfully deployed it but when running it has a problem is that it cannot found my servlet file to forward the page then I realized that I forgot to configure a servlet in the web.xml file thus I add servlet tag to web.xml file but when I try to deploy it again it show this message
"Error: Server Error The server encountered an error and could not complete your request. Please try again in 30 seconds."
so I try to remove a servlet tag in web.xml file then it can be deployed as the first time. So I think the problem is caused by the servlet tag but I put it back to web.xml file now. I don't know what to do. please help.
this is web.xml file
<?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>
this is my 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
}
}
this is 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>
Try fulling qualifying the Calculator class. E.g.,
<servlet-class>cal.Calculator</servlet-class>