大家好,
我有一个问题一直很纳闷,
用到了struts2, jquery,ext,velocity
先将代码贴出来,然后再叙述问题所在。
web.xml如下:<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID"
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">
<display-name>misDemo</display-name> <!-- struts2 -->
<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> <servlet>
<servlet-name>velocityView</servlet-name>
<servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class>
<init-param>
<param-name>org.apache.velocity.toolbox</param-name>
<param-value>/WEB-INF/toolbox.xml</param-value>
</init-param> <init-param>
<param-name>org.apache.velocity.properties</param-name>
<param-value>/WEB-INF/velocity.properties</param-value>
</init-param> <load-on-startup>10</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>velocityView</servlet-name>
<url-pattern>*.vm</url-pattern>
</servlet-mapping> <welcome-file-list>
<welcome-file>page/login/login.vm</welcome-file>
</welcome-file-list>
</web-app>
struts.xml如下:<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml" />
<constant name="struts.devMode" value="true" />
<constant name="struts.i18n.encoding" value="UTF-8"/>
<constant name="struts.action.extension" value="do,action"></constant>
<package name="demo" extends="struts-default">
<action name="loginAction" class="cn.study.action.LoginAction" method="execute">
<result name="success" type="velocity">/page/login/home.vm</result>
<result name="input" type="velocity">/page/login/login.vm</result>
</action> </package>
</struts>home.vm如下:<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<LINK rel="stylesheet" type="text/css" href="../../css/ext-all.css"/>
<SCRIPT type="text/javascript" src="../../js/jquery-1.3.js"></SCRIPT>
<SCRIPT type="text/javascript" src="../../js/ext-base.js"></SCRIPT>
<SCRIPT type="text/javascript" src="../../js/ext-all.js"></SCRIPT>
<TITLE>首页-欢迎成功登录</TITLE>
<SCRIPT type="text/javascript">
// Ext.onReady(function(){
jQuery(document).ready(function(){
new Ext.Panel({
renderTo: "frameWeb",
width: 1300,
height: 500,
layout: "border",
items: [{
region: "north",
title: "顶部面板",
height: 50
}, {
region: "south",
title: "底部面板",
height: 40
}, {
region: "center",
title: "中央面板"
}, {
region: "west",
title: "左部面板",
width: 100
}]
});
});
</SCRIPT>
</HEAD>
<BODY>
<!-- velocity 显示登录用户名 -->
$name
<DIV style="padding-top:0px;padding-left:10px" id="frameWeb">
</DIV>
</BODY>
</HTML>package cn.study.action;import java.util.ArrayList;
import java.util.List;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport {
private String name;
private String pwd; public String execute() { if ("cc".equals(name)) {
if ("c".equals(pwd)) {
return SUCCESS;
}
}
return INPUT;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
}问题如下:
如果我直接访问http://localhost:8080/misDemo/page/login/home.vm 那么home页面就可以正常显示ext所画的面板,
如果我通过登录,struts2的action跳转,则home页面就不能显示ext所画的面板(http://localhost:8080/misDemo/loginAction.do)。
在firefox中运行,说是jQuery未被定义,jQuery is not defined。拜托各位了,我搞了一天,也没想出来原因所在。等待中
我有一个问题一直很纳闷,
用到了struts2, jquery,ext,velocity
先将代码贴出来,然后再叙述问题所在。
web.xml如下:<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID"
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">
<display-name>misDemo</display-name> <!-- struts2 -->
<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> <servlet>
<servlet-name>velocityView</servlet-name>
<servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class>
<init-param>
<param-name>org.apache.velocity.toolbox</param-name>
<param-value>/WEB-INF/toolbox.xml</param-value>
</init-param> <init-param>
<param-name>org.apache.velocity.properties</param-name>
<param-value>/WEB-INF/velocity.properties</param-value>
</init-param> <load-on-startup>10</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>velocityView</servlet-name>
<url-pattern>*.vm</url-pattern>
</servlet-mapping> <welcome-file-list>
<welcome-file>page/login/login.vm</welcome-file>
</welcome-file-list>
</web-app>
struts.xml如下:<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml" />
<constant name="struts.devMode" value="true" />
<constant name="struts.i18n.encoding" value="UTF-8"/>
<constant name="struts.action.extension" value="do,action"></constant>
<package name="demo" extends="struts-default">
<action name="loginAction" class="cn.study.action.LoginAction" method="execute">
<result name="success" type="velocity">/page/login/home.vm</result>
<result name="input" type="velocity">/page/login/login.vm</result>
</action> </package>
</struts>home.vm如下:<HTML>
<HEAD>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<LINK rel="stylesheet" type="text/css" href="../../css/ext-all.css"/>
<SCRIPT type="text/javascript" src="../../js/jquery-1.3.js"></SCRIPT>
<SCRIPT type="text/javascript" src="../../js/ext-base.js"></SCRIPT>
<SCRIPT type="text/javascript" src="../../js/ext-all.js"></SCRIPT>
<TITLE>首页-欢迎成功登录</TITLE>
<SCRIPT type="text/javascript">
// Ext.onReady(function(){
jQuery(document).ready(function(){
new Ext.Panel({
renderTo: "frameWeb",
width: 1300,
height: 500,
layout: "border",
items: [{
region: "north",
title: "顶部面板",
height: 50
}, {
region: "south",
title: "底部面板",
height: 40
}, {
region: "center",
title: "中央面板"
}, {
region: "west",
title: "左部面板",
width: 100
}]
});
});
</SCRIPT>
</HEAD>
<BODY>
<!-- velocity 显示登录用户名 -->
$name
<DIV style="padding-top:0px;padding-left:10px" id="frameWeb">
</DIV>
</BODY>
</HTML>package cn.study.action;import java.util.ArrayList;
import java.util.List;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport {
private String name;
private String pwd; public String execute() { if ("cc".equals(name)) {
if ("c".equals(pwd)) {
return SUCCESS;
}
}
return INPUT;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
}问题如下:
如果我直接访问http://localhost:8080/misDemo/page/login/home.vm 那么home页面就可以正常显示ext所画的面板,
如果我通过登录,struts2的action跳转,则home页面就不能显示ext所画的面板(http://localhost:8080/misDemo/loginAction.do)。
在firefox中运行,说是jQuery未被定义,jQuery is not defined。拜托各位了,我搞了一天,也没想出来原因所在。等待中
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID"
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">
<display-name>misDemo</display-name> <!-- struts2 -->
<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>
<!-- ======================== -->
<!-- velocity -->
<servlet>
<servlet-name>velocityView</servlet-name>
<servlet-class>org.apache.velocity.tools.view.servlet.VelocityViewServlet</servlet-class>
<init-param>
<param-name>org.apache.velocity.toolbox</param-name>
<param-value>/WEB-INF/toolbox.xml</param-value>
</init-param> <init-param>
<param-name>org.apache.velocity.properties</param-name>
<param-value>/WEB-INF/velocity.properties</param-value>
</init-param> <load-on-startup>10</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>velocityView</servlet-name>
<url-pattern>*.vm</url-pattern>
</servlet-mapping> <!-- ========================= -->
<welcome-file-list>
<welcome-file>page/login/login.vm</welcome-file>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<include file="struts-default.xml" />
<constant name="struts.devMode" value="true" />
<constant name="struts.i18n.encoding" value="UTF-8"/>
<constant name="struts.action.extension" value="do,action"></constant>
<package name="demo" extends="struts-default">
<action name="loginAction" class="cn.study.action.LoginAction" method="execute">
<result name="success" type="velocity">/page/login/home.vm</result>
<result name="input" type="velocity">/page/login/login.vm</result>
</action> </package>
</struts>
import java.util.List;import com.opensymphony.xwork2.ActionSupport;public class LoginAction extends ActionSupport { private static final long serialVersionUID = 1L; private String name; private String pwd; public String execute() { if ("cc".equals(name)) {
if ("c".equals(pwd)) {
return SUCCESS;
}
}
return INPUT;
} public String getName() {
return name;
} public void setName(String name) {
this.name = name;
} public void setPwd(String pwd) {
this.pwd = pwd;
}
}