The server encountered an internal error () that prevented it from fulfilling this request.

来源:互联网 发布:新版mac如何强制关机 编辑:程序博客网 时间:2024/06/15 12:48

错误提示:

The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.NullPointerExceptioncom.pb.web.action.LoginAction.login(LoginAction.java:18)sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)java.lang.reflect.Method.invoke(Unknown Source)
解释:在if(user.getUserName().equals("aptech")&&user.getPassword().equals("ok")){
System.out.println("到这里了2");
return "success";
}else{
return "input";
}

中(user.getUserName().equals("aptech")&&user.getPassword().equals("ok")这句有问题,当换用ture时,程序可以往下走。根据提示,是不能正常初始化,我这里用的是

属性的方式传递参数。

解决办法:经仔细检查,发现在form表单中有错误。因为我采用的是JavaBean的方式传送数据,所以标签input中的name="userName"应该写成name="user.userName"。

此外,在显示页面中,属性页必须写成user.userName形式。如:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<%=request.getParameter("user.userName")%>登录成功,欢迎您!<br/>
<s:property value="user.userName"/>登录成功,欢迎您!<br/>
</body>

0 0
原创粉丝点击