Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


venkatesh
Servlet & Jsp
1 Answer(s)      5 years and a month ago
Posted in : Java Interview Questions



Advertisement
View Answers

September 7, 2009 at 5:11 PM


Hi Friend,

Try the following code:

1)form.jsp:
<%@ page language ="java" %>
<html>
<body>
<form name="f1" method="post" action="..//Servlet2">
<table align="center">
<tr>
<td>User Name</td><td><input type="text" name="user" ></td>
</tr>
<td>Password</td>
<td><input type="password" name="pass"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="b1" value="Login"></td>
</tr>
</table>

</form>
</body>
</html>

2)Servlet2.java:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Servlet2 extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException{
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String username=request.getParameter("user");
String password=request.getParameter("pass");
if((username.equals("roseindia"))&&(password.equals("roseindia"))){

String destination ="./jsp/loginSuccess.jsp";
response.sendRedirect(response.encodeRedirectURL(destination));
}
else{
String destination ="./jsp/error.jsp";
response.sendRedirect(response.encodeRedirectURL(destination));
}
}
}

3)Servlet mapping in web.xml:

<servlet>
<servlet-name>Servlet2</servlet-name>
<servlet-class>Servlet2</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Servlet2</servlet-name>
<url-pattern>/Servlet2</url-pattern>
</servlet-mapping>

Thanks


Related Tutorials/Questions & Answers:
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value
Advertisements
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value.   Hi Friend, Please visit the following links: http://www.roseindia.net/tutorial/servlet/passParameters.html
jsp/servlet - JSP-Servlet
jsp/servlet  How to create and save the excel file on given location using jsp/servlet?  hi Geetanjali, Read for more information, http://www.roseindia.net/jsp/poi/excelPOI.shtml Thanks
servlet and jsp
servlet and jsp  how to connect an jsp and an servlet without connecting to database
jsp and servlet
jsp and servlet  what is the difference between jsp and servlet ? what is the advantages and disadvantages of jsp and servlet
Servlet - JSP-Servlet
Servlet and Java Code  Example and source code in Servlet and JSP
JSP - JSP-Servlet
JSP & Servlet Example Code  Need example of JSP & Servlet
servlet and jsp - JSP-Servlet
servlet and jsp  can any one give me jsp-servlet related project-its urgent- 1-chat application 2-bug tracking system 3-online shopping 4-online...://www.roseindia.net/jsp/bank.shtml Thanks
servlet/jsp - JSP-Servlet
servlet/jsp  hi, get me the source code to upload all file formats in servlet/jsp plaese help me as soon as possible its urgent!!! by saravanan.k  Hi friend, Code to help in solving the problem
Servlet - JSP - JSP-Servlet
Servlet - JSP  i used arraylist in servlet as shown ArrayList total = new ArrayList (); ... total.add(k[i]); session.setAttribute("efg",total); when I code this like in my jsp <%ArrayList<Integer> data= new
servlet and jsp - JSP-Servlet
servlet and jsp  Hello folks, I am very new JDBC. I am doing a project on java messaging service on the part of the project we are using JDBC. In my...   write in the jsp form action="path of servlet" and wirite
java (servlet) - JSP-Servlet
java (servlet)  how can i disable back button in brower while using servlet or JSP
servlet and jsp - JSP-Servlet
servlet and jsp  Hi friend, please show one sample program, how to connect jsp and servlet using backend a ms-access.  Hi friend,<%@ page language="java" import="java.sql.*,java.util.*,java.text.*"
jsp/servlet - JSP-Servlet
jsp/servlet  Hello ! How can we call a servlet on a link on html page like a href="servletname"> Call Servlet Is it possible?   Hi friend, I am sending simple application using servlet. This is form
Jsp-Servlet
Jsp-Servlet  how can i display the values in jsp pages as list from servlet ? can you help me out plz ? thanks
JSP,Servlet - JSP-Servlet
JSP,Servlet  How can i pass a list of objects from jsp to an Action? Please help me to do
jsp servlet
jsp servlet  i dont know how to write a code to Create a JSP with one text field to enter the URL and a submit button.On clicking the submit button, send the request to a servlet .Once the servlet receives the request, it need
jsp servlet
jsp servlet  i dont know how to write a code to Create a JSP with one text field to enter the URL and a submit button.On clicking the submit button, send the request to a servlet .Once the servlet receives the request, it need
servlet/jsp - JSP-Servlet
servlet/jsp  Thanks for ur feedback! But this program shows an error showing package.org.apache.commons.fileupload.servlet does not exists package.org.apache.commons.fileupload.disk does not exists
Servlet - JSP - JSP-Servlet
Servlet - JSP  Here is my complete code. all my code is running with out any error. the for loop in servlet is running as many times as my checkboxes... Servlet Code: ---------------------- package com.servlet; import
JSP & Servlet - JSP-Servlet
JSP & Servlet  Its an IBM Question In the process of login validation. i'm entering the username correct and pass wrong. when using... is wrong ? can any one help me with coding ? i'm just a beginner with JSP
JSP & Servlet - JSP-Servlet
JSP & Servlet  In the process of login validation. i'm entering the username correct and pass wrong. when using response.sendRedirect() a new req... help me with coding ? i'm just a beginner with JSP and sServlets
jsp-servlet - JSP-Servlet
jsp-servlet  what is the problem with using microsoft access as database? The sample example, i got from you is: database:mysql. One of my java faculty said, we cannot use ms-access as database because it has some dis-advantage
jsp/servlet - JSP-Servlet
jsp/servlet  Hello friends ! I want to create columns in a table at run time everyday. I am using mysql database.how should I do it? thanks in advance  Hi friend, Plz explain your problem in details to solve
JSP - JSP-Servlet
JSP  if the jsp is converted into servlet which type of code genreted and it will exend which type of servlet?i want answer plzzzz replyyyyyyyyyy
Servlet Error - JSP-Servlet
Servlet Error  Dear All, Which are the jar files needed in Web-inf/lib folder if database is mysql. servlet-api.jar jsp-api.jar mysql-connector...   Hi prakash servlet-api.jar jsp-api.jar mysql-connector
JSP-Servlet
JSP-Servlet  Hi have created a JSP page and I need to print it when the user clicks on the print button. I have put a print button on the JSP page. Can somebody plz help me out with the Servlet page coding
servlet - JSP-Servlet
be the xml code which will describe a servlet and mapps an instance of it with specific url..???  Hi friend, Servlet and JSP Examples. Servlet and JSP Examples
Jsp ,Servlet Problem - JSP-Servlet
Jsp ,Servlet Problem  hi, m new to jsp n Servlet. i really find ur... with oracle. it worked wonders. now i m starting jsp n servlet learning.. pls... to execute a servlet code on tomcat server... Thanking u... Santosh  
Advertisements
 

 

 

DMCA.com