库存管理系统的登陆问题

这是我的login.jsp页面

<%@ page contentType="text/html; charset=UTF-8" %>
<%
	session.removeAttribute("userInfo");
%>
<html>
<head>
	<title>库存管理系统</title>
	<script type="text/javascript">
		function check(){
			var logincode = document.getElementById("logincode").value;
			var password = document.getElementById("password").value;
			var error = document.getElementById("error");
			error.innerHTML="";
			if(logincode==""){
				error.innerHTML="用户名不能为空!";
				return false;
			}
			if(password==""){
				error.innerHTML="密码不能为空!";
				return false;
			}
			return true;
		}
	</script>
	<style type="text/css">
		* { margin:0 auto; padding:0; border:0;font-size:12px;}
		body { background:#0462A5; font:12px "宋体"; color:#004C7E;}
		input { border:1px solid #004C7E;}
		.main { background:url(img/login/bg.jpg) repeat-x;}
		.login { background:#DDF1FE; width:468px; height:262px; border:1px solid #000;}
		.top { background:url(img/login/login_bg.jpg) repeat-x; width:464px; height:113px; border:1px solid #2376B1; margin-top:1px;}
		.logo { background:url(img/login/logo.gif) no-repeat; width:150px; height:42px; float:left; margin:29px 0 0 14px;}
		.lable { background:url(img/login/lable.gif) no-repeat; width:157px; height:32px; float:right; margin:81px 31px 0 0;}
		.submit { background:url(img/login/submit.gif) no-repeat; cursor:hand; width:71px; height:24px; border:0;} 
		.reset { background:url(img/login/reset.gif) no-repeat; cursor:hand; width:71px; height:24px; border:0;} 
	</style>
</head>

<body>
<div>
<table width="100%" height="100%" class="main" cellpadding="0" cellspacing="0">
  <tr>
    <td align="center">
      <div class="login">
        <div class="top">
          <div class="logo"></div>
          <div class="lable"></div>
        </div>
        <table width="466" cellpadding="0" cellspacing="0">
          <tr>
            <td style="padding-top:30px;">
            
		    <form action="user_login.do" method="post" >
              <table width="100%" cellpadding="0" cellspacing="0">
                <tr>
                  <td align="right" height="27">用户名:</td>
                  <td align="right" width="161">
                    <input type="text" id="logincode" style="width:150px;height:20px" />
                  </td>
                  <td align="center" height="29">
                    <input name="submit" type="submit" value="" onclick="return check()" class="submit" />
                  </td>
                </tr>
                <tr>
                  <td align="right" height="27">密&nbsp;&nbsp;码:</td>
                  <td align="right" width="161">
                    <input type="password" id="password" style="width:150px;height:20px" />
                  </td>
                  <td align="center" height="29">
                    <input name="reset" type="reset" value="" class="reset" />
                  </td>
                </tr>
              </table>
	        </form>
            </td>
          </tr>
        </table>
        <table width="100%" cellpadding="0" cellspacing="0" style="margin-top:8px;">
          <tr>
          	<td align="center" style="height:25"><font id="error" color="red">${error}&nbsp;</font></td>
          </tr>
          <tr>
            <td align="center">MyStock 2021</td>
          </tr>
        </table>
      </div>
      <!--login -->
    </td>
  </tr>
</table>
</body>
</html>

我数据库设置的用户名和密码都是admin,用Tomcat运行完毕后,在浏览器输入路径,显示登陆界面,将用户名和密码输入进去后,结果弹出这样一个异常

我查完知道是数据没有获取到,然后点开了login方法,但是并没有发现什么异常

package com.cxstock.action.power;


import com.cxstock.action.BaseAction;
import com.cxstock.biz.power.UserBiz;
import com.cxstock.biz.power.dto.UserDTO;
import com.cxstock.utils.pubutil.Page;
import com.cxstock.utils.system.Constants;

@SuppressWarnings("serial")
public class UserAction extends BaseAction  {
	
	private UserBiz userBiz;
	
	private Integer userid;
	private String logincode;
	private String password;
	private String username;
	private Integer roleid;
	private Integer state;
	private String bz;
	
	/** 登录验证 */
	public String login() {
		try{
			String code = logincode.trim().toLowerCase();
			String pass = password.trim().toLowerCase();
			UserDTO userInfo = userBiz.login(code, pass);
			if (userInfo != null) {
				this.getSession().setAttribute(Constants.USERINFO, userInfo);
				return "success";
			} else{
				this.getRequest().setAttribute("error", "用户名或密码错误");
				return "input";
			}
		}catch (Exception e) {
			e.printStackTrace();
			this.getRequest().setAttribute("error", "连接失败");
			return "login";
		}
	}
	
	/** 用户权限菜单 */
	public String getMenuBuf() {
		UserDTO userInfo = this.getUserDTO();
		try {
			if(userInfo!=null){
				this.outString(userInfo.getUsermenu());
			}
		} catch (Exception e) {
			e.printStackTrace();
			this.outError();
		}
		return null;
	}
	
	/** 
	 * 分页查询用户列表 
	 */
	public String findPageUser() {
		try {
			Page page = new Page();
			page.setStart(this.getStart());
			page.setLimit(this.getLimit());
			userBiz.findPageUser(page);
			this.outPageString(page);
		} catch (Exception e) {
			e.printStackTrace();
			this.outError();
		}
		return null;
	}	

	/**
	 * 保存/修改用户
	 */
	public String saveOrUpdateUser() {
		try {
			UserDTO dto = new UserDTO(userid,logincode,password,username,roleid,null,state,bz);
			boolean bool = userBiz.saveOrUpdateUser(dto);
			if(bool){
				if(userid==null){
					this.outString("{success:true,message:'保存成功!'}");
				}else{
					this.outString("{success:true,message:'修改成功!'}");
				}
			}else{
				this.outString("{success:false,errors:'用户账号已存在!'}");
			}
		} catch (Exception e) {
			 e.printStackTrace();
			 this.outError();
		}
		return null;
	}
    
	/**
	 * 删除用户
	 */
	public String deleteUser() {
		try {
			userBiz.deleteUser(userid);
			this.outString("{success:true}");
		} catch (Exception e) {
			e.printStackTrace();
			this.outError();
		}
		return null;
	}

	public void setUserBiz(UserBiz userBiz) {
		this.userBiz = userBiz;
	}

	public void setUserid(Integer userid) {
		this.userid = userid;
	}

	public void setLogincode(String logincode) {
		this.logincode = logincode;
	}

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

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

	public void setRoleid(Integer roleid) {
		this.roleid = roleid;
	}

	public void setState(Integer state) {
		this.state = state;
	}

	public void setBz(String bz) {
		this.bz = bz;
	}
	
	


}

 

传参有误,你的输入框里面没有参数名,你应该加上在input标签里面加上name属性

例如用户名的name可以设置为 name="username",提交的时候浏览器上面就会有xxxx?username=xxx,

<input type="text" name="username" style="width:150px;height:20px" />

 

你在login方法中return的返回值在struts.xml配置文件中没有找到对应的<result> ,检查下是哪一个没有配置好

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

<struts>
	<constant name="struts.action.extension" value="do" />
	<!-- 设置Web应用的默认编码集为UTF-8 -->
	<constant name="struts.i18n.encoding" value="UTF-8"/>
	<!-- 设置Struts2默认的ObjectFactory为spring -->
	<constant name="struts.objectFactory" value="spring" />
	<!-- 设置Struts2应用是否处于开发模式,通常在开发调试阶段设为true,正式上线后可设为false -->
	<constant name="struts.devMode" value="true" />
	<!-- 设置Struts2的默认主题为simple -->
	<constant name="struts.ui.theme" value="simple" />
	
	<!-- 定义一个名为 cxstock 的包,继承 Struts 2 的默认包 -->
    <package name="cxstock" extends="struts-default">
		<!-- 配置自定义拦截器LoginedCheckInterceptor -->
		<interceptors>
			<interceptor name="loginedCheck" class="com.cxstock.utils.filter.LoginedCheckInterceptor"/>
		</interceptors>	    
    
		<!-- 定义全局result -->
		<global-results>
			<!-- 定义名为exception的全局result -->
		    <result name="exception">/exception.jsp</result>
		    <result name="tologin">/jsp/main/tologin.htm</result>
		</global-results>

		<!-- 定义全局异常映射 -->
		<global-exception-mappings>
			<!-- 捕捉到Exception异常(所有异常)时跳转到exception所命名的视图上 -->
			<exception-mapping exception="java.lang.Exception" result="exception"/>
		</global-exception-mappings>	
    </package>
    
    <package name="main" extends="cxstock" namespace="/">
		<action name="*_*" class="{1}Action" method="{2}">
			<result name="input">/login.jsp</result>
			<result name="success" type="redirect">/jsp/main/index.jsp</result>
			<interceptor-ref name="loginedCheck"/>
			<interceptor-ref name="defaultStack"/>
		</action>
	</package>
</struts>

这是我的Struts.xml,哪里的问题

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632