954,574 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to start a servlet automatically when index.jsp starts.

How to start a servlet automatically when index.jsp starts.

To put it simple, here is the index.jsp file.

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>

<html>

    <head>
        <title>JSP Test</title>
    </head>

    <body>
        I want to put something here, so a servlet automatically starts without doing anything.
    </body>

</html>
iamcreasy
Junior Poster in Training
90 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

You can load the servlet directly. Instead of writing at the url:
http://localhost:port/index.jsp

you can write:
http://localhost:port/YourServlet

javaAddict
Nearly a Senior Poster
Team Colleague
3,329 posts since Dec 2007
Reputation Points: 1,014
Solved Threads: 448
 

You can load the servlet directly. Instead of writing at the url: http://localhost:port/index.jsp

you can write: http://localhost:port/YourServlet

Thanks. But is there anything else that I could write inside the body part that will execute the servlet?

iamcreasy
Junior Poster in Training
90 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

What exactly you trying to do? Please explain as it seem like you want to call from same JSP on servlet to do something for you without moving from page which is not good concept. There can be something else better suited to the situation

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 
What exactly you trying to do? Please explain as it seem like you want to call from same JSP on servlet to do something for you without moving from page which is not good concept. There can be something else better suited to the situation

Yes I want the index.jsp page to do nothing except redirecting to a servlet.

I am a noob learner, so this is something that I was just trying to do. Didn't really looked into creating something good.

iamcreasy
Junior Poster in Training
90 posts since Nov 2009
Reputation Points: 10
Solved Threads: 0
 

You know the idea is that JSP page present some data. On button or link click you request something from server that is handled by servlet. Servlet handle this and then forward data JSP page.
So if you tell us little more about what you trying to do we can help. To get basic idea of JSP-servlet interaction you can always look at MVC tutorial at top of this section and there is also FAQ section that list various learning resources if you interesd

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

it's depend on server which you use. It should be JSP on the server, or you have one at the localhost (using some developer tools)!

nore
Light Poster
38 posts since Sep 2010
Reputation Points: 10
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: