-1

I have a signIn.jsp which allows users to sign into their account. This HTML form will lead to a java servlet. It works locally but doesn't work on the paid web host server that I bought. It kept giving me a 404 error /LoginServlet cannot be found. Thanks in advance!

Below is my jsp:

    <form action="LoginServlet" method="POST" style="background-color: transparent;">                                  
    <input type="text" id="username" name="username" placeholder="Username" style=" height: 25px" value=""/>                               
    <input type="password" id="password" name="password" placeholder="Password" style=" height: 25px" value=""/>                                  
    <input type="submit" name="submit" class=" login-submit" value="Sign-In" style=" height: 25px" />                              
    </form>

Below is my web.xml

     <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/javaee" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        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_2_5.xsd"
        version="2.5">
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <display-name>ThinkAuction</display-name>
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
        <servlet>
            <servlet-name>LoginServlet</servlet-name>
            <servlet-class>User.LoginServlet</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>LoginServlet</servlet-name>
            <url-pattern>/LoginServlet</url-pattern>
        </servlet-mapping>
    </web-app>

below is my LoginServlet:

public class LoginServlet extends HttpServlet {
        //private static final long serialVersionUID = 1L;
        static private int loginSuccessful = 0; etc...}
CocoNess
  • 4,213
  • 4
  • 26
  • 43
Hazel Toh
  • 1
  • 3
  • change the action to "LoginServlet.do" – greenhorn Apr 28 '15 at 10:28
  • please provide your URL you used to access that HTML form page?? – Jafar Ali Apr 28 '15 at 12:48
  • @JafarAli I've edited and tried a simple index.jsp leading to a servlet which sends the user to google.com at thinkauction.tk – Hazel Toh Apr 28 '15 at 13:24
  • it leads to NewServlet and I do not see any NewServlet mapping in web.xml – Jafar Ali Apr 28 '15 at 13:29
  • Does this hosting provide a servlet container?? – Jafar Ali Apr 28 '15 at 13:31
  • @JafarAli The one that is on the website now is just a testing page for the servlet. i've done the same thing as what i've posted above just without any extra codes. I've put in servlet and the servlet mapping the same way. Nope it does not have any servlet container. – Hazel Toh Apr 28 '15 at 13:56
  • can you tell me how you deployed your application. what was your War name while you were deploying?? Can you confirm you have properly installed your application at the root of your Tomcat server. – Jafar Ali Apr 28 '15 at 14:33
  • wait a minute . Your hosting doesnot have Servlet container (Web server which understand Servlet like Tomcat, weblogic...). Then you need one/ – Jafar Ali Apr 28 '15 at 14:38
  • @JafarAli i build it in netbeans. then i put them into the web server then restart the tomcat for the web.xml to reload – Hazel Toh Apr 28 '15 at 15:17
  • what was your war name?? For accessing your application from root of your tomcat then your war file name should be ROOT `ROOT.war`. Then you can access your application from web server root context. – Jafar Ali Apr 29 '15 at 05:41

1 Answers1

0

Change value of action attribute in form tag to ${pageContext.request.contextPath}/LoginServlet.

${pageContext.request.contextPath} returns the portion of the request URI that indicates the context of the request.

It is same as request.getContextPath()

<form action="${pageContext.request.contextPath}/LoginServlet" method="POST" style="background-color: transparent;">

Deepika Rajani
  • 564
  • 5
  • 15