错误如下:
HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception java.lang.NullPointerException
org.apache.struts2.impl.StrutsActionProxy.getErrorMessage(StrutsActionProxy.java:69)
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:500)
org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:434)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.35 logs.
--------------------------------------------------------------------------------Apache Tomcat/6.0.35sum.jsp页面:
<%@ page language="java" import="java.util.*" pageEncoding="gbk" %>
<%@ taglib prefix="s" uri="/struts-tags"  %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>输入操作数</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->  </head>
  
  <body>
    求代数和:<br/>
    <s:form action="sums.action" >
    <s:textfield name="operand1" label="操作数1:"/>
    <s:textfield name="operand2" label="操作数2:"></s:textfield>
     <s:submit value="代数和"></s:submit>
    </s:form>
  </body>
</html>
negative.jsp页面:
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'negative.jsp' starting page</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->  </head>
  
  <body>
    代数和为负整数<h1><s:property value="sum"/></h1>
  </body>
</html>
posivite.jsp页面
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>显示代数和</title>
    
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">    
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->  </head>
  
  <body>
    代数和为负整数<h1><s:property value="sum" /></h1>
  </body>
</html>FirstAction类:
package action;
import com.opensymphony.xwork2.ActionSupport;
public class FirstAction extends ActionSupport {
private int operand1;
private int operand2;

public String execute()throws Exception
{
if(getSum()>=0)
{
return "positive";
}
else
{
return "negative";
}

}

public int getOperand1()
{
return operand1;
}
public void setOperand1(int operand1)
{
System.out.println(operand1);
this.operand1=operand1;
}
public int getOperand2()
{
return operand2;
}
public void setOperand2(int operand2)
{
System.out.println(operand2);
this.operand2=operand2;
}
public int getSum()
{
return operand1+operand2;
}}struct.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<struts>
   <package name="struts2"   extends="struts-default" >
      <action name="sums" class="action.FirstAction">
        <result name="positive" >/positive.jsp</result>
        <result name="negative">/negative.jsp</result>
      </action>
   </package>
</struts>
web.xml文件L
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" 
xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter>
   <filter-name>struts2</filter-name>
   <filter-class>
      org.apache.struts2.dispatcher.FilterDispatcher
   </filter-class>
</filter>
<filter-mapping>
   <filter-name>struts2</filter-name>
   <url-pattern>/*</url-pattern>
</filter-mapping><!--  
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
-->
  
</web-app>哪个朋友看看我哪里错了,导致出现上面错误,谢谢。

解决方案 »

  1.   

    “The full stack trace of the root cause is available in the Apache Tomcat/6.0.35 logs.”
    去找找root cause吧,那里面才有最原始错误的位置和行数。
      

  2.   

    NullPointerException空指针,最好找的问题了,自己找吧。
      

  3.   

    空指针异常,这个容易被忽略,但也比较好找吧,null不能调用方法,否则就会出现NullpointerException
      

  4.   

    先看sums.action有没有走execute()  
      

  5.   

    你的action中似乎少定义了sum这个变量,而你页面直接是取sum。