首先,你的request对象肯定没有值,
第二点,你的sql语句写错了,
第三点,你的name值没有定义,
下面是我做的测试,你可以看一下:
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
Connection con = null;
PreparedStatement pst1 = null;
String username = "44";//这是第一点
String pwd = "44";
String Nname = "41";//这是第二点
/*
* String username = request.getParameter("user"); String pwd =
* request.getParameter("pwd");
*/
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
con = DriverManager.getConnection("jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=user", "sa", "sa");
pst1 = con
.prepareStatement("update userinfo set name=?,pwd=? where name=?");//这是第二点
pst1.setString(1, username);
pst1.setString(2, pwd);
pst1.setString(3, Nname);
pst1.executeUpdate();
out.println(name);
out.println(username);
pst1.close();
con.close();
} catch (Exception e) {
out.println(e);
}
}
1.DatabaseName=user ‘user’ 是关键词用于数据库名不符合要求。
2.update t_user set username=? password=? where username=?"
更新一般用的是id如果用姓名,那如果有的人的名字在相同呢?岂不是全都改了。
3.
pst1.close();
con.close();
不能写在try里面 应写在finally里面。
你的name空,当然select不到任何数据.所以是空的.
还有set session的时候key部分换一下看看.
如果我没记错的话,给同样的key set是,什么结果都得不到.
比如
session.setAttribute("TestParam", truename);
或者试试request.setAttribute("key", value);
session周期太长了.你一直给同样的session set.也许是我上面说的那种原因.
我不知道记没记错,
请参考