I want to use ajax in struts2,but when run my code like
http://localhost:8080/test/index.html,it raise following Javascript error:
Line:95
Char:1
Error:Could not load 'dojo.widget.html.Tooltip':last tried '__package__.js'
Code:0
URL:http://localhost:8080/test/test/Test.action<http://localhost:8080/test/test/Test.action>

My code is follows:
/*index.html*/
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
   <META HTTP-EQUIV="Refresh" CONTENT="0;URL=test/Test.action">
</head>
<body>
<p>Loading ...</p>
</body>
</html>

/*Test.jsp*/
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
   <title>Ajax Examples</title>
   <s:head theme="ajax"/>
   <script language="JavaScript" type="text/javascript">
       function doSomething() {
           alert('you can manipulate the form before it gets submitted');
           return true;
       }
   </script>
</head>
<body>
Remote form replacing another div:<br/>
<div id='two' style="border: 1px solid yellow;"><b>initial content</b></div>
<s:form
       id='theForm2'
       cssStyle="border: 1px solid green;"
       action='Test'
       method='post'
       theme="ajax">
   <input type='text' name='data' value='Struts User'>
   <s:submit value="GO2" theme="ajax" targets="two"/>
</s:form>
</body>
</html>

/*Test.java*/
package test;
import java.io.*;
import com.opensymphony.xwork2.*;
public class Test extends ActionSupport implements Action, Serializable{
   private static int counter = 0;
   private String data;
   public long getServerTime() {
       return System.currentTimeMillis();
   }
   public int getCount() {
       return ++counter;
   }
   public String getData() {
       return data;
   }
   public void setData(String data) {
       this.data = data;
   }
   public String execute() throws Exception {
       return SUCCESS;
   }
}

/*struts.xml*/
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
   "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
   "http://struts.apache.org/dtds/struts-2.0.dtd";>
<struts>
   <constant name="struts.enable.DynamicMethodInvocation" value="false" />
   <constant name="struts.devMode" value="true" />
   <include file="test.xml"/>
   <!-- Add packages here -->
</struts>

/*test.xml*/
?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
       "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
       "http://struts.apache.org/dtds/struts-2.0.dtd";>
<struts>
   <package name="test" namespace="/test" extends="struts-default">

       <action name="Test" class="test.Test">
           <result>/test/Test.jsp</result>
       </action>
       <!-- Add actions here -->
   </package>
</struts>

I don't know where wrong in my code? I want to know if I lost some js or jar
file? How to correct my code? My code structure is follows:
D:\tomcat6\webapps\test\index.html
D:\tomcat6\webapps\test\test\Test.jsp
D:\tomcat6\webapps\test\WEB-INF\web.xml
D:\tomcat6\webapps\test\WEB-INF\classes\struts.xml
D:\tomcat6\webapps\test\WEB-INF\classes\test.xml
D:\tomcat6\webapps\test\WEB-INF\classes\test\Test.class
D:\tomcat6\webapps\test\WEB-INF\lib\commons-logging-1.1.jar
D:\tomcat6\webapps\test\WEB-INF\lib\freemarker-2.3.8.jar
D:\tomcat6\webapps\test\WEB-INF\lib\ognl-2.6.11.jar
D:\tomcat6\webapps\test\WEB-INF\lib\struts2-core-2.0.6.jar
D:\tomcat6\webapps\test\WEB-INF\lib\xwork-2.0.1.jar

Thanks

Reply via email to