if (password1.equals(password2)) {
return mapping.findForward("success");
}
else{
return mapping.findForward("failure");
}哪位大侠帮我看看,这样写对不对?
return mapping.findForward("success");
}
else{
return mapping.findForward("failure");
}哪位大侠帮我看看,这样写对不对?
if (password1 != null && password1.equals(password2)) {...}
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 app.RegisterForm;public class RegisterAction extends Action {
public ActionForward excute (ActionMapping mapping,ActionForm form,HttpServletRequest request,HttpServletResponse response) {
RegisterForm registerForm=(RegisterForm)form;
String username = registerForm.getUsername();
String password1 = registerForm.getPassword1();
String password2 = registerForm.getPassword2(); if (password1.equals(password2)) {
return mapping.findForward("success");
}
return mapping.findForward("failure");
}
}
这个是STRUTS的RegisterAction.总出现语法错误.
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>register</title>
</head><body>
<form action="register.do" method="get">
username<input type="text" name="username"><p>
password1<input type="password" name="password1"><p>
password2<input type="password" name="password2"><p>
<input name="register" type="submit" value="Register" />
</body>
</html>这个是STRUTS-CONFIG.XML
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config>
<form-beans>
<form-bean name="registerForm" type="app.RegisterForm"/>
</form-beans>
<action-mappings>
<action path="/register.do"
type="app.RegisterAction"
name="registerForm">
<forward name="success" path="/success.html"/>
<forward name="failure" path="/failure.html"/>
</action>
</action-mappings>
</struts-config>
这个是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/dtd/web-app_2_3.dtd">
<web-app id="WebApp_ID">
<display-name>st</display-name>
<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>2</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>
<welcome-file-list>
<welcome-file>register.jsp</welcome-file>
</welcome-file-list>
</web-app>