• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

Application of Servlet-Jdbc and HTML

I designed One web page name login.html in which I put Login and Password textbox for user. When User press button("submit") I check Login and Password with Oracle database through Servlet and Jdbc.If he is valid user then I want to open another web Page named reguser.html? how ? please help.
0
tejasmehta71
Asked:
tejasmehta71
  • 4
  • 3
1 Solution
 
muraliramCommented:
You can use the following code to do this.

response.sendRedirect("http://www.yoursite.com/reguser.html");
 where response is of type HttpServletResponse

This wil work.Try
0
 
tejasmehta71Author Commented:
Sir,
I got given error while using code.
--------
403 forbidden
will not serve files , only servlets.
--------

tejas
0
 
tejasmehta71Author Commented:
Adjusted points to 75
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
rainmalCommented:
On the "submit" button of your HTML page, invoke the servlet

The script should look something like

<FROM METHOD=POST ACTION="/your servlet virtual directory/yourservletname>

Overide the doPost() method in the servlet so that it connects to the database, and on authentication redirects the user to the page you specify  in sendRedirect method.

like
response.sendRedirect("http://www.yoursite.com:80/path/reguser.html");

port 80 is the stadard port for HTTP requests.

"path" is the virtual pathname that is mapped to the physical path of your document directory on your webserver.

If you have any doubts, you could try and invoke this page through your web browser to check whether the path is mapped to the physical path on your webserver.
 
0
 
tejasmehta71Author Commented:
Adjusted points to 100
0
 
tejasmehta71Author Commented:
Sir,
Thank for reply.
to make it more easy herewith I write code for the same.

1 file : FirstServlet.java
--------------------------
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class FirstServlet extends HttpServlet
{
      public void doGet(HttpServletRequest request,
                                       HttpServletResponse response)
                                       throws ServletException,IOException
      {
            String log = request.getParameter("lg");
            String pwd = request.getParameter("pwd");
            response.setContentType("text/html");
            PrintWriter pw = response.getWriter();
            if(log.equals("tejas mehta"))
                  // I want to start reguser.html in same directory.
                        
       }                                             
}

2 file : FirstServlet.html
---------------------------
<html>
<body>
<form name="form1"
      action = "http://localhost:8080/servlet/FirstServlet">
<table>
<tr>
      <td>Login name</td>
      <td><input type=textbox name="lg" size="10" value=""></td>
</tr>
<tr>
      <td>password</td>
      <td><input type=password name="pwd" size="10" value=""></td>
</tr>
</table>
<input type=submit value="Submit">
</body>
</html>


3 : I am using ServletRunner from c:\jsdk2.0\bin

4: I am not working in any kind of networking

5: question is when reg user press submit It has to start another html file.

6: I solve same question by starting another servlet in which wrote html coding. but this is not right way to do project.
0
 
muraliramCommented:
Try this.

if(log.equals("tejas mehta"))
response.sendRedirect("reguser.html");

This is perfectly working for me.

0
 
muraliramCommented:
Dear tejasmehta71,

I forgot one thing.You should specify
the exact path within your site

ie..response.sendRedirect("/servlet/reguser.html")..like that.

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now