Spring_SSH整合之_架构的历史(架构整合JSP+Hibernate+Struts2)_5

48 篇文章 0 订阅
47 篇文章 0 订阅

Struts.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
	"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
	"http://struts.apache.org/dtds/struts-2.3.dtd">

<struts>
	<!-- 指定打开.jsp页面默认编码 -->
	<constant name="struts.i18n.encoding" value="UTF-8" />

	<package name="registration" namespace="/bjsxt" extends="struts-default">
		<action name="user_*" class="com.bjsxt.registration.action.UserAction"
			method="{1}">
			<result name="SUCCESS" type="redirect">/registSuccess.jsp</result>
			<result name="FAIL" type="redirect">/registFail.jsp</result>
		</action>
	</package>

</struts>

UserAction.java

package com.bjsxt.registration.action;

import com.bjsxt.registration.model.User;
import com.bjsxt.registration.service.UserManager;
import com.bjsxt.registration.service.impl.UserManagerImpl;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class UserAction extends ActionSupport {
	private String username;
	private String password;
	private String password2;

	private UserManager um = new UserManagerImpl();

	public String getPassword2() {
		return password2;
	}

	public void setPassword2(String password2) {
		this.password2 = password2;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public UserManager getUm() {
		return um;
	}

	public void setUm(UserManager um) {
		this.um = um;
	}

	@Override
	public String execute() throws Exception {
		User user = new User();
		user.setUsername(username);
		user.setpassword(password);
		if (um.exists(user)) {
			return "FAIL";
		}
		um.add(user);
		return "SUCCESS";
	}
}

regist.jsp

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>用户注册</title>

<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">

</head>

<body>
	<h1>用户注册</h1><br/>
	<form action="<%=request.getContextPath() %>/bjsxt/user_execute.action" method="post">
		用户名:<input type="text" name="username"/><br/>
		密码:<input type="password" name="password"/><br/>
		确认密码:<input type="password" name="password2"/><br/>
		<input type="submit" value=" 提 交 "/>
	</form>
</body>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值