Skip to main content

Help with servlets and Apache Tomcat 7

1 reply [Last post]
Joined: 2010-11-13

Hi there... i am coding a school project with java netbeans 6.9 and apache tomcat 7.
I have a running example of a login servlet working, but when i try to implement it in my project it doesnt work.. i am pretty sure my paths are correct, but for some reason that servlet is not loaded even after i choose deploy (maybe im missing something).
Please help me

i get

<br />
 <u>The requested resource (/BetAndUinWEB/servlet/JavaBeans.LoginServlet) is not available.</u></p>

my call to the java beans is :

<p><form action="/BetAndUinWEB/servlet/JavaBeans.LoginServlet" method="post"><br />
Username: <input name="userName" size="10" type="text"> <br><br />
<br><br />
Password: <input name="passWord" size="10" type="password"> <br><br />

here is my code under the javabeans package:

<p>package JavaBeans;</p>
<p>import;<br />
import java.util.Hashtable;</p>
<p>import javax.servlet.RequestDispatcher;<br />
import javax.servlet.ServletException;<br />
import javax.servlet.http.HttpServlet;<br />
import javax.servlet.http.HttpServletRequest;<br />
import javax.servlet.http.HttpServletResponse;<br />
import javax.servlet.http.HttpSession;</p>
<p>public class LoginServlet extends HttpServlet<br />
{<br />
    private static final long serialVersionUID = -8608034654794572382L;</p>
<p>    private Hashtable<String, String> _users;</p>
<p>    public void init()<br />
    {<br />
	_users = new Hashtable<String, String>();<br />
        _users.put("khan", "k");<br />
        _users.put("rita", "r");<br />
<p>    public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException<br />
    {<br />
	String user = request.getParameter("userName");<br />
	String pass = request.getParameter("passWord");</p>
<p>	String verifiedPass;<br />
	RequestDispatcher dispatcher;<br />
	if ((verifiedPass = (String) _users.get(user)) != null && verifiedPass.equals(pass)) {<br />
	    HttpSession session = request.getSession(true);<br />
	    User userData = new User();<br />
	    userData.setUserName(user);<br />
	    session.setAttribute("user", userData);<br />
	    dispatcher = request.getRequestDispatcher("jsp/bet.jsp");<br />
	}<br />
	else<br />
	    dispatcher = request.getRequestDispatcher("/invaliduser.html");</p>
<p>	dispatcher.forward(request, response);<br />
<p>    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException<br />
    {<br />
	doGet(request, response);<br />

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2010-11-13

found the solution.. i have to edit a .xml and define the servlets there... thought it was automatic