为啥我的action怎么都不执行呢

<%@ include file="/common/taglibs.jsp"%>
<%@ page pageEncoding="GBK"%>



工作动态添加 function load(){ var url = document.URL; var i = url.indexOf("="); var type = url.substring(i+1); if(type == 1){ document.getElementById("biaotou").innerHTML = "添加 机构介绍模块 文章"; }else if(type == 2){ document.getElementById("biaotou").innerHTML = "添加 工作动态模块 文章"; }else if(type == 3){ document.getElementById("biaotou").innerHTML = "添加 全国性文件模块 文章"; }else if(type == 4){ document.getElementById("biaotou").innerHTML = "添加 省部文件模块 文章"; }else if(type == 5){ document.getElementById("biaotou").innerHTML = "添加 中心文件模块 文章"; }else if(type == 6){ document.getElementById("biaotou").innerHTML = "添加 归集模块 文章"; }else if(type == 7){ document.getElementById("biaotou").innerHTML = "添加 提取模块 文章"; }else if(type == 8){ document.getElementById("biaotou").innerHTML = "添加 贷款模块 文章"; }else if(type == 9){ document.getElementById("biaotou").innerHTML = "添加 联名卡模块 文章"; }else if(type == 10){ document.getElementById("biaotou").innerHTML = "添加 行风建设模块 文章"; }else if(type == 11){ document.getElementById("biaotou").innerHTML = "添加 对外承诺模块 文章"; }else if(type == 12){ document.getElementById("biaotou").innerHTML = "添加 意见建议模块 文章"; }else if(type == 13){ document.getElementById("biaotou").innerHTML = "添加 财务公报模块 文章"; }else if(type == 14){ document.getElementById("biaotou").innerHTML = "添加 网上课堂模块 文章"; } } function sure(){ alert("表单提交"); contentForm.submit; }
























标题:
来源:
内容:

 
保存/html:button

/html:form


配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">




    <action path="/edit/addnew" parameter="method" input="/edit/addNew.jsp"
        name="contentForm" type="com.jtpsoft.webapp.action.xtgl.ContentAction"
        scope="request" unknown="false" validate="false">
        <forward name="list" path="/edit/gzdt.jsp"></forward>
    </action>

[b]问题补充:[/b]
点了按钮之后,没有任何反应,后台也没有打出任何信息
[b]问题补充:[/b]

就跟没提交一样,没动静
[b]问题补充:[/b]
手动请求的话找不到网页,换成普通form也没反应
[b]问题补充:[/b]
那个form我也改了 [color=blue]


[/color]

还有按钮也改了[color=blue][/color]

[color=red]但是还是不行[/color]
[b]问题补充:[/b]
[b][/b][color=darkred]
[DEBUG] 15:15:18.328 session creating...
==>>/bdgjj/edit/edit/addnew.do
[DEBUG] 15:23:11.734 session attribute adding...
[ERROR] 15:23:11.734 用户信息失效,系统要求用户重新登录!
==>>/bdgjj/login.do
[DEBUG] 15:23:11.750 session attribute adding...
[/color]
[b]问题补充:[/b]
[color=red]而且我的ContentAction继承我自己的一个BaseAction

BaseAction继承了DispatchAction,所以那个配置文件那么写应该是对的吧[/color]

你的Web.xml也需要检查下,尤其是对于struts的配置
部分代码如下:
<?xml version="1.0" encoding="UTF-8"?>
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">

index.jsp

<!-- Standard Action Servlet Configuration (with debugging) -->

action
org.apache.struts.action.ActionServlet

config
/WEB-INF/struts-config.xml


debug
2


detail
2

2

<!-- Standard Action Servlet Mapping -->

action
[size=medium][b][color=red]*.do[/color][/b] [/size]

[b][size=medium][color=darkblue]注意:红的字体显示部分。[/color][/size][/b]

[size=medium][b]另外:你的JSP页面,action的值不要再加“/”了。具体的提交方式采用的上面给你写的,你写的JavaScript提交方式就不对。[/b][/size]

首先我想知道下,运行后报的什么异常


换成一个普通的试一下,多余的东西都不要加上,换成普通的话action中应该加上项目名

那你就手动的在地址栏里去请求你的action看看什么反应。
换成普通的form 也没反应吗?

没执行就对了

function sure(){
alert("表单提交");
contentForm.submit;
}

contentForm.submit; 好像不对吧,contentForm.submit();

个人建议:
(1)要么都用Struts1.X提供的标签(如果用,就要在Jsp页面中把相应的taglib加上),要么就都用最简单的Html标签,个人建议你用Html标签。
(2)看你写的提交表单的方法,个人建议最好采用最直接的方法实现。除非你觉得你能正确的书写JavaScript.
(3)如果是刚开始学,先把流程搞清楚,最基本的功能实现了之后,在添加其他的内容;

需要修改的地方:
(1)jsp代码(已经用红色字体显示)
JSP修改后的代码:
<%@ include file="/common/taglibs.jsp"%>
<%@ page pageEncoding="GBK"%>



工作动态添加 function load(){ var url = document.URL; var i = url.indexOf("="); var type = url.substring(i+1); if(type == 1){ document.getElementById("biaotou").innerHTML = "添加 机构介绍模块 文章"; }else if(type == 2){ document.getElementById("biaotou").innerHTML = "添加 工作动态模块 文章"; }else if(type == 3){ document.getElementById("biaotou").innerHTML = "添加 全国性文件模块 文章"; }else if(type == 4){ document.getElementById("biaotou").innerHTML = "添加 省部文件模块 文章"; }else if(type == 5){ document.getElementById("biaotou").innerHTML = "添加 中心文件模块 文章"; }else if(type == 6){ document.getElementById("biaotou").innerHTML = "添加 归集模块 文章"; }else if(type == 7){ document.getElementById("biaotou").innerHTML = "添加 提取模块 文章"; }else if(type =={ document.getElementById("biaotou").innerHTML = "添加 贷款模块 文章"; }else if(type == 9){ document.getElementById("biaotou").innerHTML = "添加 联名卡模块 文章"; }else if(type == 10){ document.getElementById("biaotou").innerHTML = "添加 行风建设模块 文章"; }else if(type == 11){ document.getElementById("biaotou").innerHTML = "添加 对外承诺模块 文章"; }else if(type == 12){ document.getElementById("biaotou").innerHTML = "添加 意见建议模块 文章"; }else if(type == 13){ document.getElementById("biaotou").innerHTML = "添加 财务公报模块 文章"; }else if(type == 14){ document.getElementById("biaotou").innerHTML = "添加 网上课堂模块 文章"; } }


[color=red] [/color]
标题:
来源:
内容:
 [color=red][/color]

/html:form

注意:表单action属性值是:action="edit/addnew.do?method=save";而不是action="/edit/addnew.do?method=save";前面加斜杠就代表是服务器路径了,当然找不到相应的Action了。

(2)JSP表单属性的名称一定要和FormBean的属性名称一致
(3)既然在Struts配置文件中配置Action时,指定了 parameter="method"属性,同时在你的JSP页面中action="edit/addnew.do?method=save";所以你自己写的ContentAction需要继承DispatchAction,并且里面需要有个方法(就不需要execute方法了),完整的Action代码如下:

[code="java"]import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;

public class ContentAction extends DispatchAction {
public ActionForward save(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// 设置request的字符集
request.setCharacterEncoding("utf-8");
ContentForm laf = (ContentForm) form;

    /* 获取用户提交的表单数据 */
    String title = laf.getTitle();

    if (!"".equals(title)) {
        // 转向成功页面
        request.setAttribute("title", title);
        return mapping.findForward("list");
    } else {
        // 转向失败页面
        return mapping.findForward("error");
    }
}

}[/code]
自己修改一下吧,如果有问题,再提问。

没有反应的主要原因就是:你的form表单action属性值写的不对。上面我已经提出来了,你自己看着改改吧


如果是普通的form就得加上你的工程名字action = "/工程名/edit/addnew.do"

应该是
[code="java"]
function sure(){
alert("表单提交");
contentForm.submitcolor=red[/color];
}

[/code]

function sure(){

alert("表单提交");

contentForm.submitcolor=red[/color];

}

我咋没看到你的form 里没有name属性啊。js能找着 contentForm吗? 呵,不太懂啊。是因为用了struts标签,会自动有一个吗?

这么多的if else,怎么不用switch呢!?