读书人

作登录出了有关问题,非常郁闷!

发布时间: 2012-02-07 17:45:37 作者: rapoo

作登录出了问题,非常郁闷!!
出现以下问题:
HTTP Status 404 - /LoginProject/com/login/LoginServlet

--------------------------------------------

type Status report

message /LoginProject/com/login/LoginServlet

description The requested resource (/LoginProject/com/login/LoginServlet) is not available.


--------------------------------------------
login.jsp

<%@page contentType= "text/html "%>
<%@page pageEncoding= "GBK "%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN "
"http://www.w3.org/TR/html4/loose.dtd ">

<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=GBK ">
<title> 登录 </title>
<script language= "JavaScript ">
<!--
function validateLogin(){
var strUserName=document.frmLogin.txtUserName.value;
var strPassword=document.frmLogin.txtPassword.value;
if(strUserName== " "){
alert( "请输入用户名! ");
return false;
}
if(strPassword == " "){
alert( "请输入密码! ");
return false;
}
}
-->
</script>
</head>
<body>
<form name= "frmLogin " action= "LoginServlet " method= "post " onsubmit= "javaScript: return validateLogin(); ">
<table align= "center " border= "0 " width= "273 " bgcolor= "#FFcccc ">


<tr>
<td align= "right " height= "47 " valign= "bottom " width= "94 "> 用户名: </td>
<td height= "47 " valign= "bottom " width= "172 "> <input name= "txtUserName " type= "text "> </td>
</tr>
<tr>
<td align= "right " height= "47 " valign= "bottom " width= "94 "> 密  码: </td>
<td height= "47 " valign= "bottom " width= "172 "> <input name= "txtPassword " type= "password "> </td>
</tr>
<tr>
<td align= "right " height= "44 " width= "94 "> </td>
<td height= "44 " width= "172 "> <input name= "submit " type= "submit " value= "提交 ">     <input name= "reset " type= "reset " value= "重置 "> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>

</form>
</body>
</html>


LoginServlet.class


/*
* LoginServlet.java
*
* Created on 2007年4月2日, 下午8:54
*/

package com.login;

import java.io.*;
import java.net.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.tagext.TryCatchFinally;
import javax.xml.soap.SAAJMetaFactory;

/**
*
* @author Administrator
* @version
*/
public class LoginServlet extends HttpServlet
{


public LoginServlet()
{
super();
}


protected void doGet(HttpServletRequest request, HttpServletResponse response, String sa)
throws ServletException, IOException
{

}

/** Handles the HTTP <code> POST </code> method.


* @param request servlet request
* @param response servlet response
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response, String sa)
throws ServletException, IOException
{
response.setContentType( "text/html ");
String result= " ";
String strUserName=request.getParameter( "txtUserName ");
String strPassword=request.getParameter( "txtPassword ");
if((strUserName==null)||(strUserName.equals( " "))||(strUserName.length()> 20))
{
result= "请输入用户名(不超过20字符) ";
request.setAttribute( "error_username ",result);
response.sendRedirect( "login.jsp ");
}
if((strPassword==null)||(strPassword.equals( " "))||(strPassword.length()> 20))
{
result= "请输入密码(不超过20字符) ";
request.setAttribute( "error_username ",result);
response.sendRedirect( "login.jsp ");
}
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
try
{
Class.forName( "net.sourceforge.jtds.jdbc.Driver ");
} catch (ClassNotFoundException ex)
{
ex.printStackTrace();
}
String url= "jdbc:jtds:sqlserver://localhost:1433;DatabaseName=jspstudy ";
try
{
con=DriverManager.getConnection(url,sa, " ");
}


catch (SQLException ex)
{
ex.printStackTrace();
}
try
{
String sql= "select * from userinfo where username= ' "+strUserName+ " 'and userPwd= ' "+strPassword+ " ' ";
stmt=con.createStatement();
rs=stmt.executeQuery(sql);
if(rs.next())
{
request.getSession(true).setAttribute( "username ",strUserName);
response.sendRedirect( "login_success.jsp ");
}
else
{
response.sendRedirect( "login_failure.jsp ");
}
}
catch(SQLException sqlExc)
{
sqlExc.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
try
{
if(rs!=null)
{
rs.close();
}


}
catch(SQLException sqlExc)
{
sqlExc.printStackTrace();
}
}
}

}


web.xml


<?xml version= "1.0 " encoding= "UTF-8 "?>
<web-app version= "2.4 " xmlns= "http://java.sun.com/xml/ns/j2ee " xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance " xsi:schemaLocation= "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
<servlet>
<servlet-name> LoginServlet </servlet-name>
<servlet-class> com.login.LoginServlet </servlet-class>
<load-on-startup> 2 </load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name> LoginServlet </servlet-name>
<url-pattern> /LoginServlet </url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file> Login.jsp </welcome-file>
</welcome-file-list>
</web-app>
这上面市我主要的代码,我现是在做第一个jsp 程序,这是比较,很基础的 ,都做不出来,我好郁闷!!!




[解决办法]
你的问题在什么地方?

[解决办法]
错误 404找不到页面你找下是否路径是对的
[解决办法]
String sql= "select * from userinfo where username= ' "+strUserName+ " 'and userPwd= ' "+strPassword+ " ' ";
又见SQL注入漏洞!!
[解决办法]
LoginProject/com/login/LoginServlet

提示是这个资源不可用,能不能看一下你的工程目录结构?

读书人网 >Java Web开发

热点推荐