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省略......
}
<?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省略......
}
解决方案 »
- user guide 和 developers guide 分别是什么,有什么区别,举个例子
- 请教各位神仙,C#转业JAVA问题!!!!!!!!!!!!!!!!!!!!!!!!!
- Ajax 中responseText 对象不为空且有值而 responseXML 对象为空,搞了几天没结果.... 求高手给指点一下!
- iReport中如果如何读取hibernate传入的List???
- 怎样在tomcat部署web应用
- 如何配置resin3.022在eclipse中
- 在java中, 我想作一个自动产生的订单编号,,就是把当前日期转化为为数字,如何作,,,谢谢了,,,,在家给看看,
- 用jbuiler2005改了一个类rebuild后运行 还是执行得以前的类 怎么回事
- 在eclipse中,我每新建一个工程,要使用log4j
- JAVA问题请教
- xsl乱码问题?急呀,请大家帮帮忙呀
- 如何在EJB实现继承?
// 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.是的
3.jsp页面用UTF-8编码,filter也以UTF-8编码
//某种意义上来说 deploy对用户来说和restart服务器没什么两样....
想要动态刷新struts-config,是有办法可以做到的...
因为Struts的任何配置在运行时都放在HashMap里,找到它的HashMap,刷新他...
你的数据库出现乱码可能是你安装数据库时,字符集设置的不对。