有个问题请大神帮助解决一下??
<%@ page language="java" import="java.util.*" pageEncoding="gbk"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>内容管理系统之用户注册</title>
<style type="text/css">
<!--
.style1{
color:#FF0000
font-weight:bold
}
-->
</style>
</head>
<body>
<!-- 该表单的提交要 通过regedit.action-->
<form name="user" action="regedit.action" method="post">
<table width="776" border="1">
<tr>
<td colspan="2">
<div align="center">
用户注册【<span class="style1">消息提示:${regedit.msg} </span>】
</div>
</td>
</tr>
<tr>
<td>
<div align="right">
用户名:
</div>
</td>
<td>
<input type="text" name="username" value="${user.username}"/>
</td>
</tr>
<tr>
<td>
<div align="right">
密码:
</div>
</td>
<td>
<input type="password" name="password" value="${user.password} "/>
</td>
</tr>
<tr>
<td colspan="2">
<div align="center">
<input type="submit" name="submit" value="提交">
<input type="reset" name="Submit" value="重置"/>
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
这是我的JSP页面,为注册页面
下面是RegeditAction.java
import java.io.IOException;
import java.sql.SQLException;
import java.util.Map;
import javax.annotation.Resource;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Scope;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;
import com.myEdition.bean.User;
import com.myEdition.dao.UserDAO;
import com.myEdition.dao.impl.UserDAOImpl;
import com.myEdition.domain.Regedit;
import com.myEdition.domain.impl.Regeditlmpl;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("serial")
@Controller("RegeditAction")
@Scope("prototype")
public class RegeditAction extends ActionSupport {
//定义接口Regedit
@Resource
private User user;
private Regeditlmpl RegeditImpl;
public User getUser(){
return user;
}
public void setUser(User user){
this.user=user;
}
public String execute(){
//保存用户提交的信息
User user1 = RegeditImpl.find(user.getPassword(), user.getUsername());
if(user!=null){
Map session=(Map)ActionContext.getContext().getSession();
session.put("user1", user1);
RegeditImpl.saveUser(user);
//User user1 = RegeditImpl.find(user.getPassword(), user.getUsername());
return "regedit";
//返回页面
}
else
return null;
}
public Regeditlmpl getRegeditImpl() {
return RegeditImpl;
}
public void setRegeditImpl(Regeditlmpl regeditImpl) {
RegeditImpl = regeditImpl;
}
为什么User user1 = RegeditImpl.find(user.getPassword(), user.getUsername());会是空指针呢?怎样才能获得JSP页面提交的参数呢?
[解决办法]
<input type="text" name="username" value="${user.username}"/>
改成
<input type="text" name="user.username" value="${user.username}"/>
密码一样的道理。改下
[解决办法]
两种解决方式:
一种像1L所说;
第二种在action中 implements ModelDriven<User>并覆写
public User getModel() {
return this.model;
}去掉private User user;和user的set、get方法
[解决办法]
把
//定义接口Regedit
@Resource
放到
private Regeditlmpl RegeditImpl;上面
如:
private User user;
//定义接口Regedit
@Resource
private Regeditlmpl RegeditImpl;
前台按1L所说修改!
[解决办法]
关键哪是空指针,user=null?
还是find方法里的某句空指针?
[解决办法]