验证我的身份验证页面

时间:2014-03-10 13:34:04

标签: java css jsp authentication

我创建了一个名为Login.jsp的jsp页面,这里是以下代码:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<link type="text/css" rel="stylesheet" href="inc/style.css"  > 
<title>login</title>
</head>
<body>
<form method=post action="j_security_check">  
 <table align="center" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody>

<!-- le début de la page -->
<tr>
    <td colspan="3"> <!-- cellule contient 3 colonne -->
        <table align="center" border="0" cellpadding="0" cellspacing="0" width="65%"> 
        <!-- tableau au center de largeur 65 % et les autres colonnes sont 
        égaux et contient 2 lignes -->
            <tbody>
                <tr> 
                <td >
                    <img src="image/top_logo.png" height="63px">
                </td></tr>
            </tbody>
            <tbody>
                <tr height="10px">
            </tbody>
        </table>
    </td>
</tr> 
<tr>
    <td colspan="3" height="135px"> 
        <table align="center" border="0" cellpadding="0" cellspacing="0" width="40%">
            <tbody>
                <tr>
                    <td></td>
                    <td colspan="6" align="center" style=" font-family:serif;font-size: 37px;" class="table" >
                            <div align="center"> Authentication
                            </div>
                    </td>
                </tr>
            </tbody>
        </table>
    </td>
</tr>
<tr>

<td height="100px">
</td>

</tr>


    <tr>
        <td colspan="4">



           <table border="0" align="center" width="65%" cellpadding="1" cellspacing="1">
                <tbody>

                <tr >
                    <td width="200px"></td>
                    <td ><span style="font-family: serif;font-size: 20px"  >Login:</span></td>
                    <td><input type="text" name="j_username"></td>
                    <td width="150px"></td>
                </tr>
                <tr>
                    <td height="10px"></td>
                </tr>
                <tr>
                  <td width="200px"></td>
                    <td><span style="font-family: serif;font-size: 20px" >Password:</span></td>
                    <td> <input type="password"
                            name="j_password"></td>
                    <td width="150px"></td>
                </tr>
                </tbody>
            </table>

        </td>
    </tr>

        <tr>
        <td align="center" height="100px">          
        <input style="width: 85px" type="submit" value="Confirm" class="login">
        </td>
        </tr>
</tbody>
</table>
</form>
</body>
</html>

我在项目中的WebContent下面创建了一个名为“authentication”的新文件夹,我放在home.jsp下面。 如果登录名和密码正确,将显示此页面。 另外,我改变了项目的web.xml中的一些东西:

<?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" 
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
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>authentication</display-name>
  <security-constraint>
    <web-resource-collection>
      <web-resource-name>secured</web-resource-name>
      <url-pattern>/authentication/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
      <role-name>user</role-name>
    </auth-constraint>
  </security-constraint>
  <security-role>
    <role-name>user</role-name>
  </security-role>
  <login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
      <form-login-page>/login.jsp</form-login-page>
      <form-error-page>/login_failure.jsp</form-error-page>
    </form-login-config>
  </login-config>
</web-app>

当我输入“/Gestion_de_stock/authentication/home.jsp”作为网址时会出现许多问题: 首先,登录页面不显示我在css文件“style.css”中创建的样式 此外,当我输入正确的登录名和密码时,错误页面显示和网址我不知道它来自“/Gestion_de_stock/authentication/image/top_logo.png” 我使用eclipse java EE和tomcat7作为服务器。 你能不能帮我找出我的问题,并提前谢谢你:)

0 个答案:

没有答案