求大神帮帮忙

写了个SSH的登录注册项目,但是在更改密码的时候数据没传到后台数据库,而且也没回显更改成功的信息,不知道是jsp界面中json写的不对还是action方法问题,又或者在struts配置没写对,找了好久,希望大神们能给修改下,


具体如下

Action界面

package com.zhiyou.frontaction;

import org.apache.struts2.ServletActionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.zhiyou.info.Result;
import com.zhiyou.model.User;
import com.zhiyou.service.UserService;

@Controller
@Scope("prototype")

public class PasswordAction extends ActionSupport implements ModelDriven<User>{
    @Autowired
    private UserService usersservice;

    private String newPassword;
    private String oldPassword;

    private User user;
    private String password;
    private Result result;
    
    public Result getResult() {
        return result;
    }
    public void setResult(Result result) {
        this.result = result;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    @Override
    public User getModel() {
        user=new User();
        return user;
    }
    //跳转到密码页面
    public String password(){
        // 从Session中获取user对象
        User user1 = (User) ServletActionContext.getRequest().getSession().getAttribute("_front_user");
        user = usersservice.selectUser(user1.getEmail());
        ServletActionContext.getRequest().setAttribute("user", user);
        return SUCCESS;


    }
    //开始更换新旧密码
    //先获取旧密码
    public String change_pwd(){
        User user1 = (User) ServletActionContext.getRequest().getSession().getAttribute("_front_user");
        user = usersservice.selectUser(user1.getEmail());
        user.setEmail(user1.getEmail());
        result = new Result("修改密码失败", false);
        if(oldPassword!=user1.getPassword()){
            
        }
        if(newPassword!=oldPassword){
            
           if(user.getPassword().equals(oldPassword)){
               int i =usersservice.updatepwd(user,newPassword);
                if(i>0){
                     result = new Result("修改密码成功", true);
                     ServletActionContext.getRequest().setAttribute("user",i );
                }
            }
        }
        return SUCCESS;
                 
    }
    
}


Struts配置界面

    <!-- 用户登录界面 -->

    <package name="user" namespace="/user" extends="json-default">

<!-- 跳转到密码页面 -->
        <action name="password" class="com.zhiyou.frontaction.PasswordAction"
            method="password">
            <result name="success">/WEB-INF/view/font/user/password.jsp</result>
        </action>

        <!-- 更改密码页面 -->
         <action name="password2" class="com.zhiyou.frontaction.PasswordAction"
            method="change_pwd">
            <result name="success" type="json">
            <param name="root">result</param>
            </result>

        </action>

</package>

</struts>

password.JSP界面
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html lang="en">
<%
    String path = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
            + request.getServletContext().getContextPath() + "/";
%>
<head>
<base href="<%=path%>">
<base href="${BaseContext}">
<meta name="viewport"
    content="initial-scale=1, maximum-scale=1, user-scalable=no">
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta name="keywords"
    content="Web前端视频教程,大数据视频教程,HTML5视频教程,UI视频教程,PHP视频教程,java视频教程,python基础教程">
<meta name="description"
    content="智游教育在线课程视频,为您提供java,python,HTML5,UI,PHP,大数据等学科经典视频教程在线浏览学习,精细化知识点解析,深入浅出,想学不会都难,智游教育,学习成就梦想!">
<link rel="stylesheet" href="static/css/base.css">
<link rel="stylesheet" href="static/css/profile.css">
<title>在线公开课-智游教育|java|大数据|HTML5|python|UI|PHP视频教程</title>

</head>

<body class="w100">
    <jsp:include page="uheader.jsp"></jsp:include>
    <main>
    <div class="container">
        <h2>我的资料</h2>
        <div id="profile_tab">
            <ul class="profile_tab_header f_left clearfix">
                <li><a href="user/profile.do">更改资料</a></li>
                <li class="profile_tab_line">|</li>
                <li><a href="user/avatar.do">更改头像</a></li>
                <li class="profile_tab_line">|</li>
                <li><a href="user/password.do">密码安全</a></li>
            </ul>
            <div class="proflle_tab_body">
                <div class="proflle_tab_workplace clearfix">
                    <div class="profile_avatar_area">

                        <c:if test="${empty user.head_url}">
                            <img id="avatar" src="static/img/avatar_lg.png" alt="">
                        </c:if>

                        <c:if test="${not empty user.head_url}">
                            <img id="avatar" width="200px" height="200px"
                                src="images/${user.head_url}" alt="">
                        </c:if>

                    </div>

                    <div class="profile_ifo_area">

                        <c:if test="${not empty message}">
                            <div>
                                <strong>${message}</strong>
                            </div>
                        </c:if>
                        <form action="" method="post">
                            <div class="form_group">
                                <span class="dd">旧&#x3000;密&#x3000;码:</span> <input
                                    type="password" id="oldPassword" name="oldPassword">
                            </div>
                            <div class="form_group">
                                <span class="dd">新&#x3000;密&#x3000;码:</span> <input
                                    type="password" id="newPassword" name="newPassword">
                            </div>
                            <div class="form_group">
                                <span class="dd">确认新密码:</span> <input type="password"
                                    id="newPassword" name="newPassword"
                                    onchange="change_pwd()"><br> <span id="s1"
                                    onclick="change_pwd()"></span>
                            </div>
                            <div class="form_submit dd">
                                <input type="submit" value="保&#x3000;存"
                                    onclick="submitPassword()">
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    </main>
    <jsp:include page="ufooter.jsp"></jsp:include>
    <%@include file="../include/script.html"%>
    <script type="text/javascript">
        function submitPassword() {
            var newPassword = $('#newPassword').val();
            var oldPassword = $('#oldPassword').val();
            alert(newPassword + ":" + oldPassword);
            var password = change_pwd();
            if (password == true) {
                if (newPassword != null && newPassword != '') {
                    $.post('user/password2.do', {
                        newPassword : newPassword,
                        oldPassword : oldPassword
                    }, function(result) {
                        alert(result.message);
                        console.log(data);
                        if (result.success) {
                            alert('密码修改成功!');
                        }
                    }, 'json');
                } else {
                    alert("两次密码输入不一致!")
                }

            }
        }
        function change_pwd() {
            var flag = false;
            var pwd1 = document.getElementById("newPassword").value;
            var pwd2 = document.getElementById("newPassword02").value;
            if (pwd1 == pwd2) {
                flag = true;
                document.getElementById("s1").innerHTML = "";
            } else {
                flag = false;
                document.getElementById("s1").innerHTML = "密码输入不一致!"
            }
            return flag;
        }
    </script>
</body>

</html>


UserDao方法界面

    //查询老密码
    User selectoldPwd(String password);
    //更改密码
    int updatepwd(User user,String newPassword);
   


UserDaoImpl实现层界面

package com.zhiyou.dao.impl;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.zhiyou.dao.UserDao;
import com.zhiyou.model.User;
@Repository
public class UserDaoImpl implements UserDao {
    @Autowired
    private SessionFactory factory;


//查询老密码

        @Override
        public User selectoldPwd(String password) {
            String hql="from User where password=?";
            return  (User) factory.getCurrentSession().createQuery(hql).setParameter(0,password).uniqueResult();
        }
    //更改密码
    @Override
    public int updatepwd(User user,String newPassword) {
        String hql="update User set password=? where email=?";
        Query query=factory.getCurrentSession().createQuery(hql);
        query.setParameter(0, newPassword);
        query.setParameter(1, user.getEmail());
        
        return query.executeUpdate();

    }



UserDaoService方法界面

package com.zhiyou.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zhiyou.dao.UserDao;
import com.zhiyou.model.User;
import com.zhiyou.service.UserService;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao ud;

    //查询老密码
        @Override
        public User selectoldPwd(String password) {
            // TODO Auto-generated method stub
            return ud.selectoldPwd(password);
        }
    
        //更改密码
        @Override
        public int updatepwd(User user, String newPassword) {
            
            return ud.updatepwd(user, newPassword);
        }

   

UserDaoserviceimpl实现接口界面

package com.zhiyou.service.impl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zhiyou.dao.UserDao;
import com.zhiyou.model.User;
import com.zhiyou.service.UserService;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao ud;


//查询老密码

        @Override
        public User selectoldPwd(String password) {
            // TODO Auto-generated method stub
            return ud.selectoldPwd(password);
        }
    
        //更改密码
        @Override
        public int updatepwd(User user, String newPassword) {
            
            return ud.updatepwd(user, newPassword);
        }



阅读更多
想对作者说点什么?

求大神帮帮忙,谢谢。。

04-12

Public conn As New ADODB.Connection '公用数据库连接rnDim xlapp As New Excel.ApplicationrnPublic strName As String '登陆人员名称rnrnPublic Sub main()rn'打开数据连接字符串rn'打开窗体frmain和frmloginrnconn.Open "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=qichepeijian;Data Source=."rnfrmLogin.ShowrnEnd SubrnPublic Function SetSql(strSql As String) As Stringrn'定义不带返回的数据连接rnDim cmd As New ADODB.CommandrnOn Error Resume NextrnSet cmd.ActiveConnection = connrn cmd.CommandText = strSqlrn cmd.ExecuternIf Err Thenrn Exec_SqL = Err.Descriptionrn Exit FunctionrnEnd IfrnOn Error GoTo 0rnSetSql = "OK"rnEnd FunctionrnrnPublic Function GetSql(strSql As String) As ADODB.Recordsetrn'定义带返回记录级的数据连接rnDim rs As New ADODB.RecordsetrnWith rsrn .CursorLocation = adUseClientrn If .State = 1 Then .Closern .Open strSql, conn, adOpenDynamic, adLockOptimisticrnEnd WithrnSet GetSql = rsrnEnd FunctionrnrnPublic Sub UpdateDDD(ddd As MSHFlexGrid, rs As ADODB.Recordset)rn'以数据库记录集中地记录更新相应的显示列表rnWith rsrn If .RecordCount > 0 Thenrn Dim i As Longrn Dim ii As Longrn If .RecordCount > 30 Thenrn ddd.Rows = .RecordCount + 1rn End Ifrn i = 1rn Do Until .EOFrn For ii = 0 To ddd.Cols - 1rn ddd.TextMatrix(i, ii) = " " & Trim(.Fields(ii).Value)rn Nextrn .MoveNextrn i = i + 1rn Looprn End IfrnEnd WithrnEnd SubrnFunction MoveFont(ddd As MSHFlexGrid, intRow As Long)rn'当选中列表中的某行时,该列高亮度显示(如果改变行时,还原刚才的行为正常显示)rnDim i As LongrnDim ii As LongrnFor i = 1 To ddd.Rows - 1rn If i <> intRow Thenrn ddd.Col = 0rn ddd.Row = irn If ddd.CellForeColor <> &H0& Thenrn For ii = 0 To ddd.Cols - 1rn ddd.Col = iirn ddd.CellForeColor = &H0&rn Nextrn End Ifrn Elsern For ii = 0 To ddd.Cols - 1rn ddd.Row = irn ddd.Col = iirn ddd.CellForeColor = &HFF0000rn Nextrn End IfrnNextrnddd.Row = intRowrnddd.Col = ddd.MouseColrnEnd FunctionrnrnSub OutExcel(objDDD As MSHFlexGrid, strTitleCaption As String)rnxlapp.QuitrnSet xlapp = NothingrnSet xlapp = CreateObject("Excel.Application")rnxlapp.Workbooks.Closernxlapp.Workbooks.Addrn'-----------------------------------------------------变量区域rnDim arrTitlernarrTitle = Array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z")rnDim strTitle As String '标题rnDim i As LongrnDim ii As Longrn'-----------------------------------------------------文字标头rnWith xlapprn .Range("A1", arrTitle(objDDD.Cols - 1) & "1").Selectrn With .Selectionrn .HorizontalAlignment = xlCenterrn .VerticalAlignment = xlCenterrn End Withrn .Selection.Mergern .Rows("1:1").RowHeight = 27.75rn strTitle = strTitleCaptionrn .ActiveCell.FormulaR1C1 = strTitlern With .ActiveCell.Characters(Start:=1, Length:=Len(strTitle)).Fontrn .Name = "Times New Roman"rn .FontStyle = "加粗"rn .Size = 16rn End Withrn With .Selection.Borders(xlEdgeBottom)rn .LineStyle = xlContinuousrn .Weight = xlThinrn .ColorIndex = xlAutomaticrn End Withrn '-------------------------------------------------循环给列表复长度rn For i = 0 To objDDD.Cols - 1rn .Columns(arrTitle(i)).ColumnWidth = objDDD.ColWidth(i) / 100rn Nextrn '-------------------------------------------------设置单元格的网格rn .Range(arrTitle(0) & "2", arrTitle(objDDD.Cols - 1) & objDDD.Rows + 1).Selectrn .Selection.NumberFormatLocal = "@"rn .Selection.Borders(xlDiagonalDown).LineStyle = xlNonern .Selection.Borders(xlDiagonalUp).LineStyle = xlNonern With .Selection.Borders(xlEdgeLeft)rn .LineStyle = xlContinuousrn .Weight = xlThinrn .ColorIndex = xlAutomaticrn End Withrn With .Selection.Borders(xlEdgeTop)rn .LineStyle = xlContinuousrn .Weight = xlThinrn .ColorIndex = xlAutomaticrn End Withrn With .Selection.Borders(xlEdgeBottom)rn .LineStyle = xlContinuousrn .Weight = xlThinrn .ColorIndex = xlAutomaticrn End Withrn With .Selection.Borders(xlEdgeRight)rn .LineStyle = xlContinuousrn .Weight = xlThinrn .ColorIndex = xlAutomaticrn End Withrn With .Selection.Borders(xlInsideVertical)rn .LineStyle = xlContinuousrn .Weight = xlThinrn .ColorIndex = xlAutomaticrn End Withrn With .Selection.Borders(xlInsideHorizontal)rn .LineStyle = xlContinuousrn .Weight = xlThinrn .ColorIndex = xlAutomaticrn End WithrnDim strContent As StringrnDim intStartRow As LongrnintStartRow = 2rnstrContent = ""rn For ii = 0 To objDDD.Cols - 1rn If objDDD.MergeCol(ii) = True Thenrn For i = 0 To objDDD.Rows - 1rn If Trim(strContent) = Trim(objDDD.TextMatrix(i, ii)) Thenrn .Range(arrTitle(ii) & intStartRow, arrTitle(ii) & i + 2).Selectrn With .Selectionrn .HorizontalAlignment = xlCenterrn .VerticalAlignment = xlCenterrn End Withrn .Selection.Mergern .Range(arrTitle(ii) & intStartRow).Value = Trim(objDDD.TextMatrix(i, ii))rn Elsern intStartRow = i + 2rn strContent = objDDD.TextMatrix(i, ii)rn .Range(arrTitle(ii) & intStartRow).Value = Trim(objDDD.TextMatrix(i, ii))rn End Ifrn Nextrn Elsern For i = 0 To objDDD.Rows - 1rn .Range(arrTitle(ii) & i + 2).Value = Trim(objDDD.TextMatrix(i, ii))rn Nextrn End Ifrn NextrnEnd Withrnxlapp.Visible = TruernEnd Subrnrnrnrnrn为什么老是用户定义类型未定义,求帮忙啊。。。谢谢大家

博主推荐

换一批

没有更多推荐了,返回首页