struts-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 Source Configuration =============================== -->
<data-sources />
<!-- ========== Form Bean Definitions ================================== -->
<form-beans>
<form-bean name="userForm" type="com.struts.form.UserForm"/>
</form-beans>
<!-- ========== Global Exception Definitions ============================== -->
<global-exceptions />
<!-- ========== Global Forward Definitions =============================== -->
<global-forwards>
<forward name="error" path="/error.jsp" redirect="true" />
<forward name="home" path="/index.jsp" redirect="true"/>
</global-forwards>
<!-- ========== Action Mapping Definitions =============================== -->
<action-mappings>
<action input="/index.jsp" name="userForm" path="/register" 
type="com.struts.action.RegisterAction" scope="request" 
validate="true">
<forward name="success" path="/view.jsp"/>
</action>
</action-mappings>
<!-- ========== Controller Configuration ================================ -->
<controller />
<!-- ========== Message Resources Definitions ============================ -->
<message-resources parameter="com.struts.ApplicationResources" />
<!-- ========== Plug Ins Configuration ================================= -->
</struts-config>action form如下:
// Created by Xslt generator for Eclipse.
// XSL :  not found (java.io.FileNotFoundException:  (Bad file descriptor))
// Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl
package com.struts.form;
import java.util.Date;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
/** 
 * UserForm.java created by EasyStruts - XsltGen.
 * http://easystruts.sf.net
 * created on 09-28-2004
 * 
 * XDoclet definition:
 * @struts:form name="userForm"
 */
public class UserForm extends ActionForm {
private long id;
private String userName;
private String password;
private String password2;
private String name;
private String sex;
private String address;
private String phone;
private String post;
private String email;
private Date regTime;
public void reset(ActionMapping mapping, HttpServletRequest request) {
this.id = 0;
this.userName = null;
this.password = null;
this.password2 = null;
this.name = null;
this.sex = null;
this.address = null;
this.phone = null;
this.post = null;
this.email = null;
this.regTime = null;
}
// --------------------------------------------------------- Instance Variables
// --------------------------------------------------------- Methods
/** 
 * Method validate
 * @param ActionMapping mapping
 * @param HttpServletRequest request
 * @return ActionErrors
 */
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {
ActionErrors errors = new ActionErrors();
ActionError error = null;
if ((userName == null) || (userName.trim().length() < 1)) {
error = new ActionError("error.userName.missing");
errors.add("userName", error);
}
if ((password == null) || (password.trim().length() < 1)) {
error = new ActionError("error.password.missing");
errors.add("password", error);
}
if ((password2 == null)
|| (password2.trim().length() < 1)
|| (!password2.equals(password))) {
error = new ActionError("error.password2.notmatched");
errors.add("password2", error);
}
if ((name == null)
|| (name.trim().length() < 1)
|| (name.trim().length() > 15)) {
error = new ActionError("error.name.missing");
errors.add("name", error);
}
if ((email == null) || (email.trim().length() < 1)) {
error = new ActionError("error.email.missing");
errors.add("email", error);
}
return errors;
}
getter/setter省略...... 
}

解决方案 »

  1.   

    Action类如下:
    // Created by Xslt generator for Eclipse.
    // XSL :  not found (java.io.FileNotFoundException:  (Bad file descriptor))
    // Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl
    package com.struts.action;
    import java.util.Date;import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.action.ActionMessage;
    import org.apache.struts.action.ActionMessages;import com.struts.db.User;
    import com.struts.db.UserDAO;
    import com.struts.db.UserImpl;
    import com.struts.form.UserForm;
    /** 
     * RegisterAction.java created by EasyStruts - XsltGen.
     * http://easystruts.sf.net
     * created on 09-28-2004
     * 
     * XDoclet definition:
     * @struts:action path="/register" input="com.struts.action.RegisterAction" name="userForm" input="/index.jsp" validate="true"
     * @struts:action-forward name="success" path="/view.jsp"
     */
    public class RegisterAction extends Action {
    // --------------------------------------------------------- Instance Variables
    // --------------------------------------------------------- Methods
    /** 
     * Method execute
     * @param ActionMapping mapping
     * @param ActionForm form
     * @param HttpServletRequest request
     * @param HttpServletResponse response
     * @return ActionForward
     * @throws Exception
     */
    public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response)
    throws Exception {
    UserForm userForm = (UserForm) form;
    UserDAO dao = new UserImpl();
    User user = new User();
    user.setAddress(userForm.getAddress());
    user.setEmail(userForm.getEmail());
    user.setName(userForm.getName());
    user.setPassword(userForm.getPassword());
    user.setPhone(userForm.getPhone());
    user.setPost(userForm.getPost());
    user.setRegTime(new Date());
    user.setSex(userForm.getSex());
    user.setUserName(userForm.getUserName());
    try {
    dao.save(user);
    }
    catch (Exception e) {
    ActionMessages messages = new ActionMessages();
    messages.add(
    ActionMessages.GLOBAL_MESSAGE,
    new ActionMessage("message.register.fail"));
    saveMessages(request, messages);
    return mapping.findForward(mapping.getInput());
    }
    return mapping.findForward("success");
    }
    }web-xml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/j2ee/dtds/web-app_2_3.dtd">
    <web-app>
    <display-name>test</display-name>
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
     <filter>
    <filter-name>Set Character Encoding</filter-name>
    <filter-class>filter.EncodingFilter</filter-class>
    <init-param>
    <param-name>encoding</param-name>
    <param-value>GB2312</param-value>
    </init-param>
    <init-param>
    <param-name>ignore</param-name>
    <param-value>true</param-value>
    </init-param>
    </filter>
    <!-- filter for acl control on each request -->
    <filter-mapping>
    <filter-name>Set Character Encoding</filter-name>
    <servlet-name>action</servlet-name>
    </filter-mapping>
      <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
    <param-name>application</param-name>
    <param-value>ApplicationResources</param-value>
    </init-param>
    <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>
    <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <session-config>
    <session-timeout>50</session-timeout>
    </session-config>
    <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>
    </web-app>
      

  2.   

    1.redirect=“true” 页面重定向....
    2.是的
    3.jsp页面用UTF-8编码,filter也以UTF-8编码
      

  3.   

    页面转向有两种,一种是forward, 一种是redirect,两种效果大不一样,前者是在服务器端的页面转,页就是相当于执行了这个类以后继续执行forward的类(jsp也是类嘛),但是使用同一个request,response,页就是说request里面的内容没有变化,这些页面属于同一个request生命周期。但是redirect不一样,当代码中遇到redirect时(forward代码是:requestDiaptache.forward(request,response),而redirect是response.sendRecirect("1.jsp")),是服务器发给客户端浏览器一个命令,使其连接1.jsp,发过去的代码相当于html代码里面的<meta ...>什么的,让浏览器发出HTTP指令:GET 1.jsp.于是可以看出这于以前的request完全是分离的,属于不同的request生命周期,所以以前你在request里面存的内容也就肯定不存在了。这也是你为什么获得不了error的内容,因为error的内容存在request中,你是redirect,当然不行了
      

  4.   

    修改struts-config可以不用从启动tomcat,只要redsploy这个项目就可以了,你只要将这个项目的web.xml改变一下版本就可以了(修改再存储),或是在http://localhost:8080/下面的manager可以redesplo某个项目
      

  5.   

    那是jdbc驱动的字符没有配好,连接参数中配置字符编码
      

  6.   

    修改struts-config可以不用从启动tomcat,只要redsploy这个项目就可以了,你只要将这个项目的web.xml改变一下版本就可以了(修改再存储),或是在http://localhost:8080/下面的manager可以redesplo某个项目
    //某种意义上来说 deploy对用户来说和restart服务器没什么两样....
     想要动态刷新struts-config,是有办法可以做到的...
     因为Struts的任何配置在运行时都放在HashMap里,找到它的HashMap,刷新他...
      

  7.   

    redirect=“true” 就是请求将呗重新定向,说简单些,你会发现浏览器的地址烂的地址变化了,没有这个设置时,时不会的。
    你的数据库出现乱码可能是你安装数据库时,字符集设置的不对。