胖虎
jsp文件在tomcat里运行找不到自定义包了,该怎么定义才对

这个包没写错吧

package Md5;

public class Md5 {

/**

* 将密码转换成MD5加密后的字符串形式.

* @param password 原始密码

* @return 32位字符串

*/

public static String getMD5(String password) {

byte[] source = password.getBytes();

String s = null;

char hexDigits[] = { // 用来将字节转换成 16 进制表示的字符

'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D',

'E', 'F' };

try {

java.security.MessageDigest md = java.security.MessageDigest

.getInstance("MD5");

md.update(source);

byte tmp[] = md.digest(); // MD5 的计算结果是一个 128 位的长整数,

// 用字节表示就是 16 个字节

char str[] = new char[16 * 2]; // 每个字节用 16 进制表示的话,使用两个字符,

// 所以表示成 16 进制需要 32 个字符

int k = 0; // 表示转换结果中对应的字符位置

for (int i = 0; i < 16; i++) { // 从第一个字节开始,对 MD5 的每一个字节

// 转换成 16 进制字符的转换

byte byte0 = tmp; // 取第 i 个字节

str[k++] = hexDigits[byte0 >>> 4 & 0xf]; // 取字节中高 4 位的数字转换,

// >>> 为逻辑右移,将符号位一起右移

str[k++] = hexDigits[byte0 & 0xf]; // 取字节中低 4 位的数字转换

}

s = new String(str); // 换后的结果转换为字符串

} catch (Exception e) {

e.printStackTrace();

}

return s;

}

}

然后,不知道在tomcat里边改怎么放 jsp里边才能找到我写的这个包

这个是jsp

<%@ page language="java" import="java.util.*" import = "Md5.*" import="java.sql.*" import = "java.util.Date" pageEncoding="utf-8"%>

<%

//String path = request.getContextPath();

//String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

String emsg = "ertyuio";

java.text.SimpleDateFormat formatter = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

java.util.Date currentTime = new java.util.Date();//得到当前系统时间

String t = formatter.format(currentTime); //将日期时间格式化

Class.forName("com.mysql.jdbc.Driver");

Connection conn = DriverManager.getConnection("xxXXXXXXXXXXXXXXX");

Statement stat = conn.createStatement();

String id = request.getParameter("id");

String password = request.getParameter("password");

String password1;

String ip = request.getRemoteAddr();

String sql = "";

//password1 = Md5.getMD5(password);

int a ;

int a1 = 0;

int a2 = 0;

int i = 0;

int a3 = 0;

%>

<%=id +" "+password+" "+ip+" "+t+" " %>

<%

sql = "SELECT COUNT(id) FRoM users WHERE id = '"+id+"'" ;

ResultSet rs = stat.executeQuery(sql);

rs.next();

a = rs.getInt(1);

%> <%="数据库中共有 "+a %> <%

if(a == 0){

sql = "INSERT INTO users(id,password,creat_time,ip) VALUES(?,?,?,?)";

PreparedStatement ps = conn.prepareStatement(sql);

if(id == null )

{a1 = 0;}

else if(id.getBytes("UTF-8").length>30)

{a1 = 1;}

else if(password == null )

{a2 = 0;}

else if( password.getBytes("UTF-8").length>900)

{a2 = 1;}

else if (id != null && password != null && ip != null){

password1 = Md5.getMD5(password);

emsg = "1";

ps.setString(1,id);

ps.setString(2,password1);

ps.setString(3,t);

ps.setString(4,ip);

i = ps.executeUpdate();

}

}

else if (a == 1){a3 = 1;}

else {a=0;}

%>

<%="md5加密后 "+password1+" " %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

*本站禁止HTML标签噢*

*本站禁止HTML标签噢*

*本站禁止HTML标签噢* 注册系统 </title>

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

</head>

*本站禁止HTML标签噢*

<script type = "text/javascript">

function a()

//得到文本内容

{

id = document.log.id.value;

password = document.log.password.value;

password1 = document.log.password1.value;

//alert(id +" "+password +" "+ password1 );

if( id == ""){

alert("请填写用户名 ");

document.log.uid.focus();

}

else if(password == ""){

alert("密码不能为空");

document.log.password.focus();

}

else if(password1 != password){

alert("请检查密码是否一致");

document.log.password.focus();

}

else

log.submit();

}

if(<%= i%> == "1"){

alert("成功注册");

}

if(<%= a1%> == "1"){

alert("ID输入过长");

}

if(<%= a2%> == "1"){

alert("留言输入过长");

}

</script>

<!-- 页面******************************************************************************************** -->

<form name = "log" method = "post" >

<%=emsg %> <%= "a3 = "+ a3 %>

*本站禁止HTML标签噢*

*本站禁止HTML标签噢* *本站禁止HTML标签噢* 用户名:</td> *本站禁止HTML标签噢* <input type = "text" name = "id"> </td> </tr>

*本站禁止HTML标签噢* *本站禁止HTML标签噢* 设置密码:</td> *本站禁止HTML标签噢* <input type = "password" name = "password"> </td></tr>

*本站禁止HTML标签噢* *本站禁止HTML标签噢* 确认密码</td> *本站禁止HTML标签噢* <input type = "password" name = "password1"></td></tr>

*本站禁止HTML标签噢* <td align = "right"> </td><td align = "left">   <input type = "reset" >  <input type = "button" value = "注册"; ></td></tr>

</table>

</form>

</body>

</html>

部分细节没完善和重复的先不理,因为不知道怎么用自定义包来md5加密,这个是主要问题