strtus入门问题
这个页面为什么提交后,跳转到一个空白页,没有正确得到往数据库中添加一条记录等
相关操作??
这个页面如下:
------------------------- [createUser.jsp] ------------------------
<%@page contentType="text/html;charset=gb2312"%>
<%@ taglib uri="/struts-logic" prefix="logic" %>
<%@ taglib uri="/struts-bean" prefix="bean" %>
<%@ taglib uri="/struts-html" prefix="html" %>
<html:html locale="true">
<head>
<html:base/>
<title>
<bean:message key="index.title"/>
</title>
</head>
<body>
<h2>创建一个用户</h2>
<html:errors/>
<html:form action="createUser.do" method="GET">
userName:<html:text property="user.userName" /> <br/>
password:<html:password property="user.password" /> <br/>
age: <html:text property="user.age" /> <br/>
<html:submit property="submit"/>
</html:form>
</body>
</html:html>
------------------------- [createUser.jsp] ------------------------
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.1//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<form-beans>
<form-bean name="userForm" type="edu.jmu.cheyo.struts.UserForm"/>
</form-beans>
<global-forwards>
<forward name="userCreated" path="/viewUser.jsp"/>
</global-forwards>
<action-mappings>
<action path="/createUser"
type="edu.jmu.cheyo.struts.UserAction"
name="userForm"
scope="request"
validate="true"
input="/createUser.jsp">
</action>
</action-mappings>
<message-resources parameter="ApplicationResources"/>
</struts-config>
----------------------------- [struts-config.xml] -----------------
----------------------------- [UserAction.java] -----------------
package edu.jmu.cheyo.struts;
import org.apache.struts.action.*;
import javax.servlet.http.*;
//ActionÀà¡£
public class UserAction extends Action {
public ActionForward perform(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
UserForm f = (UserForm) form;
try {
UserBean bean = new UserBean();
bean.addUser(f.getUser());
} catch(Exception e) {
e.printStackTrace();
}
request.setAttribute("User",f.getUser());
return (mapping.findForward("userCreated"));
}
}
----------------------------- [UserAction.java] -----------------