java servlet help neeed....

java servlet help neeed....

i have little bit miss concept on servlet and jsp....what ever i know always the jsp provoke first then servlet ...like the index .jsp will be called first then from there according to action the servlet will be called (mapping i have to make in web.xml)......but to some one told me always the servlet will be called first then jsp...same for index .jsp also
his concept is like

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>

the welcome file is like a controller(servlet) which will be provoked first then the index.jsp will be called ...from there any other servlet....etc


i wnt to know which concept is true...mine or his...?

and is welcome file is a controller(servlet)....which calls first
View Answers

August 11, 2011 at 1:02 PM

You can run an application either by jsp or by servlet. It may depend which type of application you are implementing. Suppose you have a login form which obviously a jsp page. And you want to perform an action using servlet to verify the user.

1)login.jsp:

<html>
<script>
function validate(){
var username=document.form.user.value;
var password=document.form.pass.value;
if(username==""){
 alert("Enter Username!");
  return false;
}
if(password==""){
 alert("Enter Password!");
  return false;
}
return true;
}
</script>
<form name="form" method="post" action="../Login" onsubmit="javascript:return validate();">
<table>
<tr><td>Username:</td><td><input type="text" name="user"></td></tr>
<tr><td>Password:</td><td><input type="password" name="pass"></td></tr>
<tr><td></td><td><input type="submit" value="Login"></td></tr>
</table>
</form>
</html>

2)Login.java:

import java.io.*;
import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Login extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try{
        response.setContentType("text/html");
        PrintWriter out=response.getWriter();
        String user=request.getParameter("user");
String pass=request.getParameter("pass");
 Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/test","root","root");  
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from login where username='"+user+"' and password='"+pass+"'");
int count=0;
          while(rs.next())
          {

                   count++;
          }

                    if(count>0)
          {
            out.println("welcome "+user);
          }
          else
          {
                       response.sendRedirect("/examples/jsp/login.jsp");
          }
    }catch (Exception e) {
    e.printStackTrace();
    }
}
}

3)In web.xml, do the servlet mapping:

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

So the above application will run through jsp which then called the servlet to perform action. You already know that jsp is converted into servlet during execution.

For more information, visit the following links:

JSP Tutorials:

Servlet Tutorials:


August 11, 2011 at 2:07 PM

ya your answer is correct....here the jsp is fist invoked...and from there the servlet invoked according to the action defined in the form...and request dispatcher 
but can u give a example where the servlet invoke first...before jsp..


actually i am having a fight with my senior...he is telling always the servlet will be invoked first...from there jsp..
and my opinion is first jsp then from there servlet.(jsp converts to servlet when compile that is not the issue)
he is telling the welcome-file is a servlet ...

and my one more question is ,is welcome-file servlet...?

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>









Related Tutorials/Questions & Answers:
java servlet help neeed....
java servlet help neeed....  i have little bit miss concept on servlet and jsp....what ever i know always the jsp provoke first then servlet ...like... the servlet will be called (mapping i have to make in web.xml)......but to some one told
help on project - JSP-Servlet
help on project  Need help on Java Project
Advertisements
Help in completing Servlet code!
Help in completing Servlet code!  Complete the following Servlet codes to store the information read from the input form to session object. public void doGet(HttpServletRequest req, HttpServletResponse resp) throws
help me - JSP-Servlet
help me   how to open one compiled html file by clicking one button from jsp
jsp help - JSP-Servlet
jsp help  hai friends i am using videos,which will play on my webpage using flowplayer.my doubt is where will i store my videos whether in the database or in another local folder. please help me as soon as possible thanks
Please Help - JSP-Servlet
Please Help  Respected Sir/Madam, I am R.Ragavendran.. Thanks for your response.. You told me that its difficult to handle the problem.. Ok,Let me try my hands on it.. The help i need is can u please tell me
please help - JSP-Servlet
To Year "> please help
plz help me!!!!!!!! - JSP-Servlet
plz help me!!!!!!!!  i`ve set the environment varaibles for tomcat as well as jdk.. but i`m not understanding where i`ve to save my servlet..i.e. html file,.java file and xml file.. under which directory or folder i`ve to save
Project realated help - JSP-Servlet
Project realated help   Hi sir i need your assistance em stuck at a point,actualy i am making final year project,i am making OTRS system in java em using sturts ,servlet,i push whole data by layered architecture,sir succesfully
servlet redirect problem help needed
servlet redirect problem help needed  package p; import...=getServletContext().getRequestDispatcâ?¦ re.forward(req, resp); } } this servlet is calling by a jsp..there is no problem,in this servlet the if condition always
servlet redirect problem help needed
servlet redirect problem help needed  package p; import...=getServletContext().getRequestDispatcâ?¦ re.forward(req, resp); } } this servlet is calling by a jsp..there is no problem,in this servlet the if condition always
Help with javascript function - JSP-Servlet
Help with javascript function  I've got a button in a for loop.Each button gets its name property dynamically: The Code is as follows... this task? ***Your help would very much appreciated
help in insert code - JSP-Servlet
help in insert code  I have some doubt in following code. I want to insert value using prepared statement.we r accessing connection from other package.can u plz help me out.  hiimport java.io.*;import java.sql.*;import
Programming Help URGENT - JSP-Servlet
Programming Help URGENT  Respected Sir/Madam, I am R.Ragavendran. I am in urgent need of the coding. My requirement is as follows: Beside... TO ROSEINDIA TEAM< IF I GET THIS HELP IN TIME.... Thanks/Regards
please help in jsp - JSP-Servlet
please help in jsp  i have two Jsp's pages. on main.jsp have some list of schools. from there i can go home page of any school. home.jsp represents..._TO_REPLACE_1 addmission please help.  Hi Friend
Need Help-How to store input parameter in DB through Java Bean - JSP-Servlet
Need Help-How to store input parameter in DB through Java Bean  Hello...(Its Java Bean) which create a connection from DB and insert the data. At run time servlet and server also show that loggging are saved in DB. But when I
help me on jstl- <c:url> - JSP-Servlet
help me on jstl c:url  what is jstl in java
java help!
java help!   I need help starting off a program I am trying to write for class. The class should contain a private instance variable to represent temperature in Degrees Celsius and it should have the following methods
Help With Java...
Help With Java...  Write a java program that can take a positive integer greater than 2 as input and write out the number of times one must repeatedly divide this number by 2 before getting a value less than 2
help in java
help in java   Rational Numbers Rational numbers are numbers that can be represented as a fraction p / q where p is an integer number and q is a positive integer (q != 0). Design and implement a Java class RationalNumber
java (servlet) - JSP-Servlet
java (servlet)  how can i disable back button in brower while using servlet or JSP
How to create own help forum - JSP-Servlet
How to create own help forum  Hi All, My client given requirements, they need to create their own help forum, I need to do case study for, how to create any forum. if you have any documentation or technical ideas please
help in java
help in java  Write an application that prompt the user to enter a number to use as an array size, and then attempt to declare an array using the entered size. Java generates a NegativeArraySizeException if wou attempt to create
java help?
java help?  Write a program, where you first ask values to an array with 6 integer values and then count the sum and average of the values in methods (send in the array & return the counted value to the main program). Print
java help
java help   Write a Java program that does the following: 1.Creates a grading program based on the Baker College grading standard. You will need to look up the current grade standard. You may use only the letter grades without
help for java
help for java  1.convert the following Pseudo code to java if/else structure if student?s grade is greater than or equal to 90 Print ?A? else if student?s grade is greater than or equal to 80 Print ?B? else
help in java
help in java  3.Flights Design and implement a class called Flight that represents an airline flight. It should contain instance data that represents the airline name, flight number, and the flight's origin and destination cities
help in java
help in java  Write a program that will evaluate simple expressions such as 17 + 3 and 3.14159 * 4.7. The expressions are to be typed in by the user. The input always consist of a number, followed by an operator, followed
help in java
help in java  Design and implement a class called Sphere that contains instance data that represents the sphere's diameter. Define the Sphere constructor to accept and initialize the diameter, and include getter and setter
help in java
help in java  The factorial of a nonnegative integer n is written n! (pronounced ââ?¬Å? n factorialââ?¬Â?) and is defined as follows: n!=n . (n-1) . (n-2) . .... . 1 (for values of n greater than or equal to 1) and n!=1 (for n
help in java
help in java  Shopping cart Create 3 shopping carts from a Cart class. Each class should have four items in it, a title, a price for the 4 items and the number of each. Your shopping cart should use private variables, so use
help in java
help in java  Gross And Dozens Design and implement a class called GrossAndDozens to convert a given number of eggs into the number of gross, the number of dozens, and to the number of left over eggs. If you have N eggs, then you
help in java
help in java   Team Roster Create a program called TeamRoster that uses a class called Roster. Roster should contain a team name and the names of all... or help me on this pleas.. 7. Gross And Dozens Design and implement a class
Programming help Very Urgent - JSP-Servlet
Programming help Very Urgent  Respected Sir/Madam, Actually my code shows the following output: There is a combo box which contains all the ID's present in the database.. When I click or select any of the ID,it automatically
help in java
help in java  Define a class named Money whose objects represent amounts of U.S. money. The class will have two instance variables of type int for the dollars and cents in the amount of money. Include a constructor with two
help in java
help in java  Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have a number
help in java
help in java  Temperature Write a Temperature class that has two instance variables: a temperature value (a floating-point number) and a character for the scale, either C for Celsius or F for Fahrenheit. The class should have
help in java
help in java  Create 3 shopping carts from a Cart class. Each class should have four items in it, a title, a price for the 4 items and the number of each. Your shopping cart should use private variables, so use getter and setter
help in java
help in java  Create a class named Order that performs order processing of a single item. The class has five instance variables (fields) : customer name, customer number, quantity ordered, unit price, and total price. Define
Java Servlet - JSP-Servlet
Java Servlet   Hello Sir Could you help me in understanding directory Structure for servlet page in eclipse (IDE). I save my Sevlet in WEB-INF but it is not displaying, it is displaying code of servlet. Process used
java help
java help  How to Open CSV Files in a Microsoft Excel Application Using Java Code with example pgm
Help Very Very Urgent - JSP-Servlet
Help Very Very Urgent  Respected Sir/Madam, I am sorry..Actually the link u have sent was not my actual requirement.. So,I send my requirement again.. Actually my code needs the following output: There is a combo box which
Need help in image uploading - JSP-Servlet
Need help in image uploading  hii, i have one doubt in uploading an image in jsp. I want to display image from DB to my jsp page. For that i upload images to a specified folder and save the path of image in my DB. Its
java help
java help  1) build class(es) for the dresses, choose (dress ID, color, price, designer)( link lists) 2) construct the driver class by establishing two separate objects for each sister 3) let them both to enter the dresses
java help
java help  Rational numbers are numbers that can be represented as a fraction p / q where p is an integer number and q is a positive integer (q != 0). Design and implement a Java class RationalNumber for representing such numbers
Java help
Java help  Write a Temperature class that represents temperatures in degrees in both Celsius and Fahrenheit. Use a Floating-point number for the temperature and a character for the scale: either 'C' for Celsius or 'F
Java Help
Java Help  Write a Temperature class that represents temperatures in degrees in both Celsius and Fahrenheit. Use a Floating-point number for the temperature and a character for the scale: either 'C' for Celsius or 'F
java help
java help  Design and implement a class called DateWriter that has three instance variables: a string for month, an integer for day, and an integer for year. The class should has a constructor to accept and initialize the values
Java servlet
Java servlet  What is servlet
JAVA SERVLET - JSP-Servlet
JAVA SERVLET Log   Hi, A servlet file which create the log files ,then writing values to the list & log, we should have a thousand separator and no decimal values. This means instead of writing 986300.0 in the Log file

Ads