一个论坛程序是用jsp+servletjavabean模式的
程序里面的所有的servlet类都出现了啊警告不知什么原因例如
一个LoginServlet就出现警告提示为:
add default serial version ID
add generated serial version ID
rename in file
源码如下:
package com.wxpn.tutorial.servlet;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.wxpn.tutorial.db.ConnectionPool;
import com.wxpn.tutorial.db.DB;
/**
* Servlet implementation class for Servlet: LoginServlet
*/
public class LoginServlet extends javax.servlet.http.HttpServlet implements
javax.servlet.Servlet {
public LoginServlet() {
super();
}
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
String result = "";
// 获取提交的用户名:
String strUserName = request.getParameter("txtUserName");
// 获取提交的密码:
String strPassword = request.getParameter("txtPassword");
// 创建数据库连接对象:
ConnectionPool connPool = DB.getConnPool();
Connection conn = connPool.getConnection();
Statement stmt = null;
ResultSet rs = null;
try {
// sql语句:
String sql = "select * from userinfo where username='"
+ strUserName + "' and userpwd='" + strPassword + "'";
// 创建数据记录集对象:
stmt = conn.createStatement();
// 执行sql语句,返回一个记录集到rs:
rs = stmt.executeQuery(sql);
// 如果记录集为非空,表明有相匹配的用户名和密码,登录成功:
if (rs.next()) {
// 登录成功时,把strUserName设成session变量UserName
request.getSession(true).setAttribute("userName", strUserName);
response.sendRedirect("index.jsp");
} else {
// 否则(记录集为空),表明失败:
request.setAttribute("error", "登录失败");
try {
request.getRequestDispatcher("/error.jsp").forward(request,
response);
} catch (Throwable t) {
getServletContext().log(t.getMessage());
}
}
} catch (SQLException sqlExc) {
sqlExc.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
// 关闭连接,释放数据库资源:
try {
if (rs != null) {
rs.close();
}
if (stmt != null) {
stmt.close();
}
connPool.freeConnection(conn);
} catch (SQLException sqlExc) {
sqlExc.printStackTrace();
}
}
}
}
这个问题该怎么解决啊??本人刚开始学java问题很多,还请大家多多帮助我啊~
----------------解决方案--------------------------------------------------------
我有点抗不住了,什么书上这么写的,还是什么老师这么教你们的!
进行数据库操作的语句,不要用什么'"+参数名+"'这样的写发!!
很不安全,容易被人恶意的进行数据库注入啊!!
唉!!
可读性也很差,为什么都喜欢这样写呢?
用绑定参数的方式写啊,这不是好很多吗?
唉!
----------------解决方案--------------------------------------------------------
作为学生, LS的要求过高啦。
----------------解决方案--------------------------------------------------------
你门只是数落拉我一下,并没有帮我把这个问题解决出来呀~~!
----------------解决方案--------------------------------------------------------
把你的Connection对象设置成全局的(属性).试试吧!
----------------解决方案--------------------------------------------------------
我有时候真纳闷了,不都说了绑定了吗?
这不是说得很明白了吗,别说不明白,要贴代码才知道哦!!
----------------解决方案--------------------------------------------------------
不同意3楼的说法,学生就很菜吗????
----------------解决方案--------------------------------------------------------
你是不是设置一下doGet()方法啊
----------------解决方案--------------------------------------------------------
我有时候真纳闷了,不都说了绑定了吗?
这不是说得很明白了吗,别说不明白,要贴代码才知道哦!!
回答问题客气点啊...
别带感情色彩
----------------解决方案--------------------------------------------------------
他好恶心..我宁愿不要他帮我,他工资能拿多高哦,学的有多叼哦...有本事进微软~~~.
----------------解决方案--------------------------------------------------------