我的页面在提交后是一片空白(标题和内容都是空白)?我修改了structs-config.xml文件中的视图文件,依然是空白,为什么?原因大概出在哪了?谢谢!

解决方案 »

  1.   

    你看是不是Action中的mapping的名称和struts-config.xml不一致,这种情况不会抛异常,会出现空白。
      

  2.   

    代码是从structs in action电子书进行修改过来的:只要 符合password1=password2,就带出success.jsp页面。
    1. web.xml<?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
       <servlet>
          <servlet-name>action</servlet-name>
          <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
          <init-param>
             <param-name>config</param-name>
             <param-value>/WEB-INF/struts-config.xml</param-value>
          </init-param>
          <init-param>
             <param-name>debug</param-name>
             <param-value>3</param-value>
          </init-param>
          <init-param>
             <param-name>detail</param-name>
             <param-value>3</param-value>
          </init-param>
          <load-on-startup>0</load-on-startup>
       </servlet>
       <servlet-mapping>
          <servlet-name>action</servlet-name>
          <url-pattern>*.do</url-pattern>
       </servlet-mapping>   
       <welcome-file-list>
      <welcome-file>Register.jsp</welcome-file>
       </welcome-file-list>
       <taglib>
       <taglib-uri>/WEB-INF/struts-tiles.tld</taglib-uri>
       <taglib-location>/WEB-INF/struts-tiles.tld</taglib-location>
       </taglib>
       <taglib>
       <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
       <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
       </taglib>
       <taglib>
       <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
       <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
       </taglib>
       <taglib>
       <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
       <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
       </taglib>
       <taglib>
       <taglib-uri>/WEB-INF/struts-template.tld</taglib-uri>
       <taglib-location>/WEB-INF/struts-template.tld</taglib-location>
       </taglib>
       <taglib>
       <taglib-uri>/WEB-INF/struts-template.tld</taglib-uri>
       <taglib-location>/WEB-INF/struts-template.tld</taglib-location>
       </taglib>
    </web-app>2.structs-config.xml<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts
    Configuration 1.1//EN"
    "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
    <struts-config>
    <!-- 数据源 -->
    <data-sources>
    </data-sources>
    <!-- 表单 Bean -->
    <form-beans>
    <form-bean name="RegisterForm" type="app.RegisterForm">
    </form-bean>
    </form-beans>
    <!-- 全局异常 -->
    <global-exceptions>
    </global-exceptions>
    <!-- 全局转发 -->
    <global-forwards>
    <forward name="failure" path="/failure.jsp">
    </global-forwards>
    <!-- 操作映射 -->
    <action-mappings>
    <action path="/register" type="app.RegisterAction"
    name="RegisterForm" scope="request" input="/Register.jsp">
    <forward name="success" path="/v/success.jsp">
    </forward>
    <forward name="failure" path="/failure.jsp">
    </forward>
    </action>
    </action-mappings>
    <!-- 消息资源 -->
    <message-resources parameter="test.resources.ApplicationResources"/>
    </struts-config>3.RegisterForm.java
    package app;
    import org.apache.struts.action.ActionForm;
    public class RegisterForm extends ActionForm {
    private String password2;
    private String password1;
    private String username;
    public String getUsername() {
    return username;
    }
    public void setUsername(String i) {
    this.username = i;
    }
    public String getPassword1() {
    return password1;
    }
    public void setPassword1(String i) {
    this.password1 = i;
    }
    public String getPassword2() {
    return password2;
    }
    public void setPassword2(String i) {
    this.password2 = i;
    }
    }4.RegisterAction.java
    package app;
    import org.apache.struts.action.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class RegisterAction extends Action {
    public ActionForward excute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest req,
    HttpServletResponse res)
    {
    RegisterForm rf = (RegisterForm)form;
    String username = (String)rf.getUsername();
    String password1 = (String)rf.getPassword1();
    String password2 = (String)rf.getPassword2();
    ActionForward forward = new ActionForward();if (password1.equals(password2)) {
    try {
    forward = mapping.findForward("success");
    } catch (Exception e) {
    forward = mapping.findForward("failure");
    }
    } else{
    forward = mapping.findForward("failure");
    }
    return (forward);}
    }5.Register.jsp
    <%@ page language="java" contentType="text/html; charset=big5"%>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <HTML>
    <HEAD>
    <TITLE>register</TITLE>
    </HEAD>
    <BODY>
    <P><html:form action="/register.do">
    yonghuming:<html:text property="username"></html:text><BR>
    mima1:<html:text property="password1"></html:text><BR>
    mima2: <html:text property="password2"></html:text><BR>
    <html:submit value="Register"></html:submit>
    </html:form></P>
    </BODY>
    </HTML>6.success.jsp
    <%@ page language="java" contentType="text/html; charset=big5"%>
    <HTML>
    <HEAD>
    <TITLE>注册成功</TITLE>
    </HEAD>
    <BODY>
    <P>注册成功</P>
    <P><BR>
    <BR>
    <A href="Register.jsp">再试一次</A>
    </P>
    </BODY>
    </HTML>7.failure.jsp
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <HTML>
    <HEAD>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@ page
    language="java"
    contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"
    %>
    <TITLE>注册失败</TITLE>
    </HEAD>
    <BODY>
    <P>注册失败</P>
    <P><BR>
    <BR>
    <A href="Register.jsp">再试一次</A>?
    </P>
    </BODY>
    </HTML>
      

  3.   

    你的xml有问题,你可以用IE浏览器打开structs-config.xml看是否会报错。
    我试了一下,你的<?xml version="1.0" encoding="UTF-8"?>的encoding要改成
    GBK或者GB2312。UTF-8似乎不行。
    <!-- 全局转发 -->
    <global-forwards>
    <!--改为<forward name="failure" path="/failure.jsp"/>-->
    <forward name="failure" path="/failure.jsp">
    </global-forwards>
    以上部分你的forward没有闭合!
      

  4.   

    to l1i2n3y4u5n6() 
    这是有问题,但改了还是不行啊,依然是一片空白,问题在哪呢?
    qqulijun() :
    页面流程怎么不对,能说清楚点么?
      

  5.   

    web.xml:
    <init-param>
        <param-name>config</param-name>
        <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    你这里使用的文件名和2.structs-config.xml,文件名都不一样啊,是不是你写上来的时候写错了?如果是这样的话,那就还要找找,比如修改RegisterAction.java在里面System.out一下,看看程序执行到action里面去没有。
      

  6.   

    你的意思是打出了个白页吗?如果是样就是你在struts-config.xml里forward的path写错啦。
    如果是画面是对的就是没有显示内容那可能是ActionForm没有放值
      

  7.   

    Action的return不是那样写的,才看你的代码,不好意思
    return mapping.forward("success");
      

  8.   

    设断点调试一把,应该是return的问题,mapping.forward与你的struts-config不匹配。
      

  9.   

    我想问一下,你是否将标签库导入到WEB-INF文件夹下?
    你可以在RegisterForm.java,RegisterAction.java两个文件中添加输出语句System.out.pringln()来确定程序运行到哪里出错了,然后再查找出错的原因
      

  10.   

    终于找到了问题所在,是RegisterAction.java中的execute方法写错了