Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8337943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:26:29+00:00 2026-06-09T04:26:29+00:00

I have JSP page – <html> <head> </head> <body> <% String valueToPass = Hello

  • 0

I have JSP page –

<html>
<head>
</head>
<body>
         <%
               String valueToPass = "Hello" ; 
         %>
    <a href="goToServlet...">Go to servlet</a>
</body>
</html>

And servlet –

    @WebServlet(name="/servlet123",
             urlPatterns={"/servlet123"})
    public class servlet123 extends HttpServlet {

        protected void doGet(HttpServletRequest request,
                HttpServletResponse response) throws ServletException, IOException {

        }

        public void foo() {

        }
}

What should I write in <a href="goToServlet...">Go to servlet</a> in order to pass values (like valueToPass or maybe add the value as argument in the ) to the servlet123 ?

Can I invoke the specific method in servlet123 (like foo()) using the link in the JSP?

EDIT:

How can I call servlet in URL? My pages hierarchy is like the following –

WebContent
 |-- JSPtest
 |    |-- callServletFromLink.jsp
 |-- WEB-INF
 :    :

And I want to call the servlet123 in the folder src->control .

I tried <a href="servlet123">Go to servlet</a> but it did not find the servlet when I press on the link.

2nd EDIT:

I tried <a href="http://localhost:8080/MyProjectName/servlet123">Go to servlet</a> and it work .

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T04:26:31+00:00Added an answer on June 9, 2026 at 4:26 am

    If you want to send parameters to the servlet using an URL, you should do it in this way

    <a href="goToServlet?param1=value1&param2=value2">Go to servlet</a>
    

    And then retrieve the values that will be available in the request.

    Regarding your second question. I will say no. You can add a param in the URL, something like

    <a href="goToServlet?method=methodName&param1=value1">Go to servlet</a>
    

    And the use of that information to call a specific method.

    By the way, if you use a framework like Struts, that will be easier since, in Struts, you can bound an URL to a specific Action method (let’s say “servlet”)

    Edited:

    You have defined your servlet in this way:

    @WebServlet("/servlet123")
    

    You, your servlet will be available on /servlet123. See doc.

    I have tested your code and it is working:

    @WebServlet(name = "/servlet123", urlPatterns = { "/servlet123" })
    public class Servlet123 extends HttpServlet {
    
        @Override
        protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    
            resp.setContentType("text/html");
            PrintWriter out = resp.getWriter();
            out.write("<h2>Hello Friends! Welcome to the world of servlet annotation </h2>");
            out.write("<br/>");
            out.close();
        }
    }
    

    Then, I called the servlet in http://localhost:8080/myApp/servlet123 (being myApp your application context if you are using one).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have jsp page - <html> <head> </head> <body> <a href=http://localhost:8080/MyProject/Servlet123?usrID=33333>Go to servlet</a> </body>
I have a JSP page with an HTML form: <form action=SERVLET> <input type=text name=name/><br>
I have jsp page (say, source.jsp ) with form: <html> <head> <body> <form action=Servlet123
I have a jsp page as: <html> <head> <title>Try in JNLP</title> <script src=http://www.java.com/js/deployJava.js></script> <script>
I have a JSP page, from where onClick I want to execute a servlet
I have a JSP page that renders a block of HTML. In normal usage,
I have jsp page and html form with button on this. How execute java
I have jsp using struts bean tag library: <html> <head> <meta http-equiv=Content-Type content=text/html; charset=UTF-8>
I have a .jsp page that passes the variable from the servlet. Lets assume
I have a jsp page with the tags: <logic:iterate id=var ... .... <bean:write name=var

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.