SSH登录,注册完整版2(写不下,后面分3,4,......)
2010-02-12 17:28
281 查看
接下来是和实体类对应的form类(由于本程序是struts1.2所有form单独那出来,后续的struts2中将不再单独需要form类).
form类如下:
package com.hp.shangtongwei.form;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
public class myform extends ActionForm {
String id;
String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
String password;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return super.validate(mapping, request);
}
}
接下来是负责页面逻辑和跳转的action类:
如下:
package com.hp.shangtongwei.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.hp.shangtongwei.dao.persondao;
import com.hp.shangtongwei.form.myform;
import com.hp.shangtongwei.vo.person;
public class personaction extends DispatchAction {
private persondaoImpl persondaot;
public persondaoImpl getPersondaot() {
return persondaot;
public void setPersondaot(persondaoImpl persondaot) {
this.persondaot = persondaot;
}
public ActionForward dologin(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
myform mf=(myform)form;
person p=new person();
p.setId(mf.getId());
p.setPassword(mf.getPassword());
boolean flag=false;
try {
flag=persondaot.isLogin(p);
} catch (Exception e) {
e.printStackTrace();
}
if(flag==true){
request.setAttribute("mp", p);
return mapping.findForward("suc");
}
else{
request.setAttribute("mp", p);
return mapping.findForward("fal");
}
}
public ActionForward doinsert(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
myform mf=(myform)form;
person p=new person();
p.setId(mf.getId());
p.setPassword(mf.getPassword());
boolean flag=false;
boolean flagcheck=false;
try {
flagcheck=persondaot.docheck(p);
} catch (Exception e1) {
e1.printStackTrace();
}
System.out.print(flagcheck);
if(flagcheck==false)
{
try {
flag=persondaot.isInsert(p);
request.setAttribute("mp", p);
return mapping.findForward("sucinsert");
} catch (Exception e) {
e.printStackTrace();
}
}
return mapping.findForward("falinsert");
}
}
另外本程序进行了国际化,分别建立了resources_en_US.properties,resources_zh_CN.resources及其基类resources.properties.
负责改变语言的action类为:
package com.hp.shangtongwei.action;
import java.util.Locale;
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;
public class changlanguageaction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
//Locale l=null;
// String language=request.getParameter("sellanguage");
// System.out.println("dd"+language);
// if(language.equals("english")){
// l=new Locale("en","US");
// Locale.setDefault(l);
return mapping.findForward("change");
// }
// else{
// l=new Locale("zh","CN");
//Locale.setDefault(l);
//return mapping.findForward("change");
// }
}
}
这个action不带form.
接下来在src下建立struts-config.xml文件和applicationContext(可以为其他的名称:)
建立后要在web.xml中添加对应的信息,如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>opensession</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>opensession</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/applicationContext.xml
</param-value>
</context-param>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<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>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
struts-config.xml配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean name="personform" type="com.hp.shangtongwei.form.myform"></form-bean>
</form-beans>
<action-mappings>
<action attribute="personform"
name="personform"
parameter="status"
path="/person"
scope="request"
type="com.hp.shangtongwei.action.personaction">
<set-property property="cancellable" value="true" />
<forward name="suc" path="/success.jsp"/>
<forward name="fal" path="/failure.jsp" />
<forward name="sucinsert" path="/successinsert.jsp"/>
<forward name="falinsert" path="/failureinsert.jsp" />
</action>
<action path="/sell" scope="request" type="com.hp.shangtongwei.action.changlanguageaction">
<forward name="change" path="/index.jsp"></forward>
</action>
</action-mappings>
<controller
processorClass="org.springframework.web.struts.DelegatingRequestProcessor">
</controller>//此处来加载applicationContext.xml把struts的跳转交给spring来管理
<message-resources parameter="com.hp.shangtongwei.action.resources">
</message-resources>
//此处用<message-resources patameter=""/>来标识资源文件的位置
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml" />
</plug-in>
//此处插件来加载applicationContext.xml把struts的跳转交给spring来管理
</struts-config>
接下来是applicationContext.xml文件,如下:
待续
form类如下:
package com.hp.shangtongwei.form;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
public class myform extends ActionForm {
String id;
String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
String password;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
@Override
public ActionErrors validate(ActionMapping mapping,
HttpServletRequest request) {
// TODO Auto-generated method stub
return super.validate(mapping, request);
}
}
接下来是负责页面逻辑和跳转的action类:
如下:
package com.hp.shangtongwei.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.springframework.context.support.AbstractXmlApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.hp.shangtongwei.dao.persondao;
import com.hp.shangtongwei.form.myform;
import com.hp.shangtongwei.vo.person;
public class personaction extends DispatchAction {
private persondaoImpl persondaot;
public persondaoImpl getPersondaot() {
return persondaot;
public void setPersondaot(persondaoImpl persondaot) {
this.persondaot = persondaot;
}
public ActionForward dologin(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
myform mf=(myform)form;
person p=new person();
p.setId(mf.getId());
p.setPassword(mf.getPassword());
boolean flag=false;
try {
flag=persondaot.isLogin(p);
} catch (Exception e) {
e.printStackTrace();
}
if(flag==true){
request.setAttribute("mp", p);
return mapping.findForward("suc");
}
else{
request.setAttribute("mp", p);
return mapping.findForward("fal");
}
}
public ActionForward doinsert(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
myform mf=(myform)form;
person p=new person();
p.setId(mf.getId());
p.setPassword(mf.getPassword());
boolean flag=false;
boolean flagcheck=false;
try {
flagcheck=persondaot.docheck(p);
} catch (Exception e1) {
e1.printStackTrace();
}
System.out.print(flagcheck);
if(flagcheck==false)
{
try {
flag=persondaot.isInsert(p);
request.setAttribute("mp", p);
return mapping.findForward("sucinsert");
} catch (Exception e) {
e.printStackTrace();
}
}
return mapping.findForward("falinsert");
}
}
另外本程序进行了国际化,分别建立了resources_en_US.properties,resources_zh_CN.resources及其基类resources.properties.
负责改变语言的action类为:
package com.hp.shangtongwei.action;
import java.util.Locale;
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;
public class changlanguageaction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
//Locale l=null;
// String language=request.getParameter("sellanguage");
// System.out.println("dd"+language);
// if(language.equals("english")){
// l=new Locale("en","US");
// Locale.setDefault(l);
return mapping.findForward("change");
// }
// else{
// l=new Locale("zh","CN");
//Locale.setDefault(l);
//return mapping.findForward("change");
// }
}
}
这个action不带form.
接下来在src下建立struts-config.xml文件和applicationContext(可以为其他的名称:)
建立后要在web.xml中添加对应的信息,如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>opensession</filter-name>
<filter-class>
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>opensession</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/classes/applicationContext.xml
</param-value>
</context-param>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>
org.springframework.web.context.ContextLoaderServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<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>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
struts-config.xml配置文件如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<form-beans>
<form-bean name="personform" type="com.hp.shangtongwei.form.myform"></form-bean>
</form-beans>
<action-mappings>
<action attribute="personform"
name="personform"
parameter="status"
path="/person"
scope="request"
type="com.hp.shangtongwei.action.personaction">
<set-property property="cancellable" value="true" />
<forward name="suc" path="/success.jsp"/>
<forward name="fal" path="/failure.jsp" />
<forward name="sucinsert" path="/successinsert.jsp"/>
<forward name="falinsert" path="/failureinsert.jsp" />
</action>
<action path="/sell" scope="request" type="com.hp.shangtongwei.action.changlanguageaction">
<forward name="change" path="/index.jsp"></forward>
</action>
</action-mappings>
<controller
processorClass="org.springframework.web.struts.DelegatingRequestProcessor">
</controller>//此处来加载applicationContext.xml把struts的跳转交给spring来管理
<message-resources parameter="com.hp.shangtongwei.action.resources">
</message-resources>
//此处用<message-resources patameter=""/>来标识资源文件的位置
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml" />
</plug-in>
//此处插件来加载applicationContext.xml把struts的跳转交给spring来管理
</struts-config>
接下来是applicationContext.xml文件,如下:
待续
相关文章推荐
- SSH登录,注册完整版1(写不下,后面分2,3,......)
- SSH登录,注册完整版2(写不下,后面分3,4,......)
- SSH登录,注册完整版3(写不下,后面分4,5,......)
- SSH登录,注册完整版4(写不下,后面分5,6,......)
- SSH登录,注册完整版5
- 点击“登录”或者“注册”按钮,出一个“登录”或者“注册”对话框给你填写,后面置灰
- 【Struts2+Hibernate3+Spring3】利用SSH整合,完成打印用户表,用户登录、注册、修改密码系统
- SSH初步搭建(登录注册)
- SSH与SSM学习之SSH实现CRM练习15——注册登录
- [SSH_easyUI]细节1:首页布局、登录注册
- ssh密钥登录,所选的用户密钥未在远程主机上注册;ssh登录日志,成功登录,失败登录
- 简单的SSH整合登录注册
- 【Struts2+Hibernate3+Spring3】利用SSH整合,完成打印用户表,用户登录、注册、修改密码系统
- SSH整合Demo——完成登录注册
- 在SSH实现简单的注册和登录的错误总结
- 简单的SSH整合登录注册
- 简单的SSH整合登录注册
- [置顶] Win10下用IDEA搭建Struts2+Spring4+Hibernate5(SSH)框架,实现用户登录注册
- eShop电子商城的SSH实现的用户模块(1)登录和注册配置文件和页面关键代码(V...
- eShop电子商城的SSH实现的用户模块(1)登录和注册Bean(Version 1.0)