简体   繁体   English

JSP登录身份验证脚本失败(MySQL后端)web.xml servlet映射?

[英]JSP Login Authentication Script failing (MySQL-backend) web.xml servlet mapping?

I am just starting out with JSP in NetBeans 6.9.1 and im trying to make a basic login script for user authentication (sessions will be added later; These are made automatically for every JSP page right?) 我只是从NetBeans 6.9.1中的JSP开始,我正在尝试制作用于用户身份验证的基本登录脚本(会话将在以后添加;这些是为每个JSP页面自动创建的,对吗?)

The problem I am having is the following. 我遇到的问题如下。 I followed the tutorial at: http://www.roseindia.net/jsp/loginbean.shtml 我按照以下教程进行操作: http : //www.roseindia.net/jsp/loginbean.shtml

** I made the necessary changes (Database related) ** **我进行了必要的更改(与数据库有关)**

When running the project I get the login screen presented, as it should. 运行项目时,我会看到登录屏幕,它应该出现。 Although when filling out the details for database authentication, I keep on running into a 404 error: "descriptionThe requested resource () is not available." 尽管在填写数据库身份验证的详细信息时,我仍然遇到404错误:“ descriptionThe请求的资源()不可用”。

I think the problem might be lying in my web.xml for not mapping the servlets right. 我认为问题可能出在我的web.xml中,因为没有正确映射servlet。 (This was not mentioned in the tutorial though.) (尽管本教程中未提及。)

See below for my web.xml: 请参阅下面的我的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" <CANT POST namespace hyperlinks. New user...>
    <context-param>
        <param-name>javax.faces.PROJECT_STAGE</param-name>
        <param-value>Development</param-value>
    </context-param>
    <servlet>
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>/faces/*</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>Login</servlet-name>
        <servlet-class>Login</servlet-class>
    </servlet>
    <servlet>
        <servlet-name>LoginBean</servlet-name>
        <servlet-class>Login</servlet-class>
    </servlet>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>Login.jsp</welcome-file>
    </welcome-file-list>
</web-app>

I hope you guys have time to look at it! 希望你们有时间看看!

(First time posting here so if there is anything im doing wrong, please let me know. (第一次在这里发布,因此如果我做错了什么,请告诉我。

Regards, 问候,

B. B.

First of all, roseindia.net is the worst source ever to learn Java EE (JSP/Servlet/JSF/etc). 首先,roseindia.net是学习Java EE(JSP / Servlet / JSF / etc)以来最糟糕的资源。 Its tutorials are cluttered of bad practices and do in no way explain/use the basic concepts properly. 它的教程杂乱无章,绝不会正确解释/使用基本概念。 It's maintained by copypaste-addicted amateurs with advertisement incomes as #1 priority. 它由复制粘贴成瘾的业余爱好者维护,广告收入排在第一位。 For me, that side is ridiculous, but for new-to-Java EE users it may be very misleading because they don't know what's good or bad. 对于我来说,这一方面太荒谬了,但是对于Java EE的新用户来说,这可能会引起很大的误导,因为他们不知道优缺点。

Your functional requirement is sound, but the posted web.xml makes no sense. 您的功能要求是合理的,但是发布的web.xml没有意义。 Firstly, you seem to have declared an ordinary Javabean class (which does not extends HttpServlet ) as a Servlet. 首先,您似乎已经声明了一个普通的Javabean类(不extends HttpServlet )作为Servlet。 Secondly, the class is not been placed inside a package, although this may not be the root cause of your problem, packageless classes are invisible to other classes inside a package and instantiating them will only work in very specific environments. 其次,该类未放置在包中,尽管这可能不是问题的根本原因,无包类对于包中的其他类是不可见的,实例化它们仅在非常特定的环境中起作用。

Further I also see the FacesServlet being declared in web.xml . 此外,我还看到FacesServletweb.xml中声明。 This is part of JSF, a component based MVC framework which is designed on top of Servlet API and can use JSP files as views. 这是JSF的一部分,JSF是一个基于组件的MVC框架,该框架是在Servlet API之上设计的,可以将JSP文件用作视图。

What do you want? 你想要什么? Develop a login page using JSF or using "plain" JSP/Servlet? 使用JSF 使用“普通” JSP / Servlet开发登录页面?

Anyway, I strongly recommend to blacklist roseindia.net as a learning source and continue with proper tutorials and books. 无论如何,我强烈建议将roseindia.net列为学习资源,并继续使用适当的教程和书籍。 Eg the tutorials provided by Oracle itself and the JSF2 - The Complete Refernce book of JSF spec lead himself. 例如,Oracle自己提供的教程以及JSF2的JSF2完全参考书就是他本人。 Further details about tutorials and books depends on whether you'd like to use JSF or not. 有关教程和书籍的更多详细信息取决于您是否要使用JSF。

See also: 也可以看看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM