问题标签用户 基于MyEclipse的登录界面的设计

dhhjj 2014-04-11 10:15:26
在MyEclipse下创建servlet,代码如下:
package servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.sql.*;

public class LoginServlet extends HttpServlet {

private String name;
private String pass;

/**
* Constructor of the object.
*/
public LoginServlet() {
super();
}

/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}


/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

this.name=request.getParameter("account");
this.pass=request.getParameter("password");
PrintWriter out=response.getWriter();
//驱动程序名
String driverName="oracle.jdbc.driver.oracleDriver";
//数据库用户名
String userName="system";
//密码
String userPasswd="zmh";
//数据库名
String dbName="XE";
//表名
String tableName="lib_user";
//联结字符串
String url="jdbc:oracle:thin:@localhost:1512:XE";
try
{
Class.forName("oracle.jdbc.driver.oracleDriver");
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql="SELECT * FROM +lib_user";
ResultSet rs = statement.executeQuery(sql);
while(true)
{
if(rs.next())
{
if((this.name.equals(rs.getString(1)))&&(this.pass.equals(rs.getString(2))))
{

out.print("<h1>"+"Login Success!");

break;
}
}
else
{
out.print("<h1>"+"Account or Password Is Invalid!");
break;
}
}
return;
}
catch(SQLException e)
{
}
catch(ClassNotFoundException e)
{
}
}

/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

doPost(request,response);
}


/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
创建login.jsp代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>


function login_click() { form1.action="Login"; form1.submit(); }
Account:
Password:


配置web.xml:
<?xml version="1.0" encoding="UTF-8"?>

LibraryService


A Login Servlet
LoginServlet
LoginServlet
servlets.LoginServlet


LoginServlet
/LoginServlet


login.jsp


在浏览器输入:http://localhost:8088/LibraryService/login.jsp能显示登录界面,但是输入账号和密码后显示如下:
HTtype Status report

message /LibraryService/Login

description The requested resource is not available.

Apache Tomcat/7.0.53TP Status 404 - /LibraryService/Login
求高手指教,本人刚接触这类软件,实在是找不出问题来,求指教~~~~~~~~~~~~
...全文
194 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
dhhjj 2014-04-11
  • 打赏
  • 举报
回复
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"> <display-name>LibraryService</display-name> <servlet> <description>A Login Servlet</description> <display-name>LoginServlet</display-name> <servlet-name>LoginServlet</servlet-name> <servlet-class>servlets.LoginServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>LoginServlet</servlet-name> <url-pattern>/LoginServlet</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>login.jsp</welcome-file> </welcome-file-list> </web-app> 这是web.xml,请大家帮忙看一看,谢谢~~~~~~~~
小灯光环 2014-04-11
  • 打赏
  • 举报
回复
404找不到你的Login的servlet,检查一下web.xml里配置的servlet映射。这个MyEclipse毫无关系啊。。你不管用什么IDE写这样的代码都会报错的。
shixitong 2014-04-11
  • 打赏
  • 举报
回复
放眼望去,没见到Login在哪配置,是不是配置的LoginServlet?把web.xml贴的详细点
浪里花 2014-04-11
  • 打赏
  • 举报
回复
message /LibraryService/Login description The requested resource is not available 你的事Login不是LoginServlet肯定找不到,你的form标签的action改成LoginServlet

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧