出现以下问题:
HTTP Status 404 - /LoginProject/com/login/LoginServlet--------------------------------------------------------------------------------type Status reportmessage /LoginProject/com/login/LoginServletdescription 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 程序,这是比较,很基础的 ,都做不出来,我好郁闷!!!
HTTP Status 404 - /LoginProject/com/login/LoginServlet--------------------------------------------------------------------------------type Status reportmessage /LoginProject/com/login/LoginServletdescription 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 程序,这是比较,很基础的 ,都做不出来,我好郁闷!!!
解决方案 »
- web动态创建文件夹,及文件!急求。。。
- 如何在Tomcat中加载一个重量级的类
- 请高手帮看一下,ActionServlet怎么才能像Action里传递参数?
- 我的Tomcat服务器启动后出现“XML validation disabled”,是哪里出了问题。
- javaBean编译找不到符号
- 关于时间的更新
- 菜鸟来问问题关于JSP配置??????HELP!
- 急!到底要多少内存WS+DB2才能跑起来?
- JSP的运行问题
- 求助:Java怎么样实现爬虫,抓取博客里面的所有文章,希望指点下该从哪里学习,推荐一些书籍之类的
- 关于JSTL <c:forEach>的用法
- tomcat频繁死掉的问题,常例分析
又见SQL注入漏洞!!