<struts-config>
<form-beans>
<form-bean name="judgeActionForm" type="ch1.JudgeActionForm">
<form-bean name="createNumberActionForm" type="ch1.CreateNumberActionForm">
</form-beans>
<global-forwards>
<forward name="guess" path="/guess.jsp"/>
</global-forwards>
<action-mappings>
<action name="judgeActionForm" path="/judgeAction" scope="session" type="ch1.judgeAction"/>
<action name="createNumberActionForm" path="/createNumberAction" scope="session" type="ch1.createNumberAction">
</action-mappings>
</struts-config>
jsp文件
<%@ taglib uri="WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ page contentType="text/html; charset=GB2312" %>
<html:html>
<head>
<title>guess.jsp</title>
</head>
<body>
<h1><bean:message key="page"/></h1>
<html:form action="/createNumberAction.do" method="POST">
<h3><bean:message key="page.choose"/></h3>
  <html:select property="digits">
<html:option value="10">10</html:option>
<html:option value="100">100</html:option>  
<html:option value="1000">1000</html:option>
</html:select>
<html:submit>
<bean:message key="page.new"/>
</html:submit><br>
</html:form>
<html:form action="/judgeAction.do" method="POST">
<html:text property="guess_number" value=""/>
<html:submit><bean:message key="page.guess"/></html:submit><br>
   </html:form>  <hr> <%    String message = null;     message = (String)session.getAttribute("message");
     if (message != null) {      
 if (message.equals("equal")){ %>   
<h1><bean:message key="result.equal"/></h1><%}
      else if (message.equals("bigger")){%>
          <h1><bean:message key="result.big"/></h1><%       }
       else {%>          <h1><bean:message key="result.small"/></h1><%       }
     }%>
</body>
</html:html>

解决方案 »

  1.   

    嗯,先看你的web.xml文件.有个<servlet>节点
    <servlet>
    <servlet-name>ActionServlet</servlet-name>
    <servlet-class>
    com.framework.web.action.ActionServlet
    </servlet-class>
    </servlet>
    里面的ActionServlet是继承了httpServlet

    <servlet-mapping>
    <servlet-name>ActionServlet</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    就是也*.do后缀的请求会被ActionServlet截获
    然后来匹配你在struts-config.xml 文件里定义的<action>节点的path属性,如果匹配就进行,你在action节点
    中定义的name属性指定的type类执行execute(...)方法.(这里你用的是继承Action的)
    而那个Action的name属性对应你的ActionForm,ActionForm能自动组装你提交的表单匹配的属性
    在execute()方法里做一些逻辑操作,而execute(ActionMapping mapping,...)方法中的mapping封装了转发
    如:mapping.findForward("success");而这个success在struts-config.xml中是定义好的
    <forward name="success" path="/main.jsp" />是<action>节点的子节点(但然也有全局和局部转发)但,要熟悉,还的多多练习,自然就会了...
      

  2.   

    谢谢,我想问问楼上的,就是createNumberAction我没有在后面加.do扩展名,为什么会自己在url请求中添加上去谢谢
      

  3.   

    因为你用的struts标签,他会自动给你加的,在没有的情况下,如果你用纯html,他是不会给你加的
      

  4.   

    还有,框架这东西,你想了解其中的"内涵",还要看源码啦,反正也没关系,都是java写的
    可以看下这个东西
    http://blog.csdn.net/hl_ghost/archive/2008/08/27/2840303.aspx
      

  5.   

    配置struts
    * 拷贝struts lib下的所有jar到WEB-INF/lib下
    * 修改web.xml文件,配置中央控制器类
    * 提供struts-config.xml文件
    下面是一个简单的配置实例:struts-config.xml<?xml version="1.0" encoding="ISO-8859-1" ?><!DOCTYPE struts-config PUBLIC
              "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
              "http://jakarta.apache.org/struts/dtds/struts-config_1_2.dtd"><struts-config> <form-beans>
    <form-bean name="loginForm" type="com.bjsxt.struts.LoginActionForm"/>
    </form-beans>

    <action-mappings>
    <action path="/login"
    type="com.bjsxt.struts.LoginAction"
    name="loginForm"
    scope="request"
    validate="true"
    >
    <forward name="success" path="/login_success.jsp"/>
    <forward name="error" path="/login_error.jsp"/>
    </action>

    </action-mappings>
    </struts-config>配置时一定要包含上面的内容.红色的字是一定要相同的..记住..
    web.xml文件直接从sun提供的struts包下的空文件就行了.
      

  6.   

    <form-bean name="">
    <action name="">
    中的name可以随便命名吗?只要他们的名字是一样的就可以了是吧!
    但是这个名字除了这里好像也没有在jsp页面中出现过了哦!想问哈这个name有什么作用?在哪个地方用到了谢谢
      

  7.   


    ActionServletl这个是一个Servlet在web.xml里配的.
    那里配里*.do,任何以.do的请求都会截获到这个servlet里<form-bean name="yourformname" type="ch1.CreateNumberActionForm"> 
    <action name="yourformname" path="/createNumberAction" scope="session" type="ch1.createNumberAction"> 
    两个名字是一致的啊
    jsp中也可以用到的
    例:ch1.CreateNumberActionForm c = (ch1.CreateNumberActionForm )request.getAttribute("yourformname");建议楼主先学一下servlet先.打好基础
      

  8.   

    >>>>>>>>>>>>建议楼主先学一下servlet先.打好基础