- public class UserAction extends ActionSupport{
- private String name;
- private String password;
- private UserService userService;
- private UserBean userBean;
- private Map map;
- public UserBean getUserBean() {
- return userBean;
- }
- public void setUserBean(UserBean userBean) {
- this.userBean = userBean;
- }
- public Map getMap() {
- return map;
- }
- public void setMap(Map map) {
- this.map = map;
- }
- public UserService getUserService() {
- return userService;
- }
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public void setUserService(UserService userService) {
- this.userService = userService;
- }
- //登录操作
- public String login(){
- List<userbean> ulist=userService.findUser(username, password);
- boolean userflag;
- if (null==ulist.get(0)) {
- userflag=false;
- }else{
- userflag=true;
- }
- if(ulist.size()>0){
- userflag=true;
- ActionContext.getContext().getSession().put("name", username);
- ActionContext.getContext().getSession().put("pwd", password);
- Integer uid= ulist.get(0).getUid();
- ActionContext.getContext().getSession().put("uid",uid);
- }else{
- userflag=false;
- }
- map=new HashMap();
- map.put("userflag",userflag);
- map.put("status","ok");
- return SUCCESS;
- }
- //用户注册
- public String zhuce(){
- userService.addUser(userBean);
- return SUCCESS;
- }
- }
- <!--login解析json-->
- <package name="json" namespace="/api" extends="json-default">
- <action name="login" class="userAction" method="login">
- <result type="json">
- <param name="root">map
- </result>
- </action>
- <!--<package-->
- <!--注册的跳转-->
- <package name="component" namespace="" extends="struts-default">
- <action name="zhuce" class="userAction" method="zhuce">
- <result name="success">
- /login.jsp
- </result>
- <!--<package-->
- <span id="txlogin"></span><br>
- <div id="log" class="easyui-dialog" title="用户登录" style="width:400px;height:300px;padding:10px;background-image:url('res/img/dn2.jpg ');">
- <div style="margin-bottom:20px">
- <input id="name" class="easyui-textbox" prompt="请输入用户名" data-options="required:true,validType:'length[3,10]',label:'用户名:'" style="width:90%;height:34px;padding:10px;color:white;">
- </div>
- <!-- <div style="margin-bottom:20px">
- <input id="name" class="easyui-textbox" prompt="请输入用户名" iconWidth="28" data-options="label:'用户名:'" style="width:90%;height:34px;padding:10px;color:white;">
- </div> -->
- <div style="margin-bottom:20px">
- <input id="password" class="easyui-passwordbox" prompt="请输入密码" iconwidth="28" data-options="label:'密码:'" style="width:90%;height:34px;padding:10px; margin-top:60px">
- </div>
- <div>
- <div style="text-align:center;margin-top:30px">
- <a href="#" οnclick="login()" class="easyui-linkbutton" style="width:100%;height:40px" target="_blank"><span style="font-size:16px">登录</span></a>
- </div>
- <div style="text-align:center;margin-top:30px">
- <a href="zhuce.jsp" class="easyui-linkbutton" style="width:100%;height:40px" target="_blank"><span style="font-size:16px">注册</span></a>
- </div>
- </div>
- </div>
- <script type="text/javascript">
- $(function() {
- //alert("123");
- });
- $.extend($.fn.textbox.defaults.rules,{
- length:{
- validator:function(value,param){
- if(isNaN(value)){
- return false;
- }else{
- return true;
- }
- },
- message:'请输入'
- }
- })
- function login(){
- $.ajax(
- {
- url:'api/login',
- dataType:'json',
- data:{
- name:$("#name").val(),
- password:$("#password").val()
- },
- success:function(data){
- if(data.status=="ok"){
- if (data.aa) {
- alert("用户登录成功");
- // $("#txlogin").html("用户登录成功");
- $("#txlogin").css("color","blue");
- location.href="zhu.jsp";
- }else {
- $("#txlogin").html("用户名或者密码不符合");
- $("#txlogin").css("color","red");
- }
- }
- },
- error:function(data){
- $("#txlogin").html("系统异常");
- }
- }
- )
- }
- </script>
- <h2>注册新用户</h2>
- <form action="zhuce" method="post">
- <div style="margin:20px 0;"></div>
- <div class="easyui-panel" title="新用户注册" style="width:100%;max-width:400px;padding:30px 60px;">
- <div style="margin-bottom:20px">
- <label for="name" class="label-top">用户名:</label>
- <input id="name" name="userBean.name" class="easyui-validatebox tb" data-options="prompt:'请输入用户名',required:true,validType:'length[3,10]'">
- </div>
- <div style="margin-bottom:20px">
- <label for="password" class="label-top">密码</label>
- <input id="password" name="userBean.password" class="easyui-validatebox tb" data-options="prompt:'请输入密码',required:true,validType:'password'">
- </div>
- <div>
- <input type="submit" value="注册" style="width:100%;height:34px;padding:10px">
- </div>
- </div>
- </form>
- <style scoped="scoped">
- .tb{
- width:100%;
- margin:0;
- padding:5px 4px;
- border:1px solid #ccc;
- box-sizing:border-box;
- }
- </style>
- <script>
- $(function(){
- $('input.easyui-validatebox').validatebox({
- validateOnCreate: false,
- err: function(target, message, action){
- var opts = $(target).validatebox('options');
- message = message || opts.prompt;
- $.fn.validatebox.defaults.err(target, message, action);
- }
- });
- });
- </script></action></package></package></userbean>
ssh框架登录注册
最新推荐文章于 2019-12-28 17:46:43 发布