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

  • Home
  • SEARCH
  • 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 6933135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:47:37+00:00 2026-05-27T11:47:37+00:00

This is my first Portlet. I am not getting values inside my servlet. Please,

  • 0

This is my first Portlet. I am not getting values inside my servlet. Please, see the program. Inside my custom portlet Java class doView() method, I show a JSP page

public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
throws IOException, PortletException {            
    include(viewJSP, renderRequest, renderResponse);
}

Inside the view.jsp page, I refer to a servlet to receive the values:

<form action="formServlet" method="post">
    <h1>Please Login</h1>
    Login:    <input type="text" name="login"><br>
    Password: <input type="password" name="password"><br>
    <input type=submit value="Login">
</form>

Inside web.xml file:

<servlet>
    <servlet-name>formServlet</servlet-name>
    <servlet-class>FormServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>formServlet</servlet-name>
    <url-pattern>formServlet</url-pattern>
</servlet-mapping>

Inside my servlet

protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {  
    String name = (String)request.getParameter("login");
    System.out.println("The Name is "+name);    
}

But I don’t know why the servlet is not being called.

  • 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-05-27T11:47:37+00:00Added an answer on May 27, 2026 at 11:47 am

    NOTE: This is an answer to a somewhat complicated question. If you are trying to learn the basics of portlet creation, I posted a better answer in another question.


    You are submitting a form using the POST method but your servlet just implements doGet(), which serves the GET method. You should either submit your form using GET or implement the doPost() method (which would be preferable in other situations).

    Also, it is necessary to precede the <url-pattern> content by a slash if it is an absolute pattern. That is, it should be

    <url-pattern>/formServlet</url-pattern>
    

    instead of

    <url-pattern>formServlet</url-pattern>
    

    That said, forget servlets now!

    You are doing it in one of the worst ways. It is really a bad idea to write a portlet which calls a servlet. After a long time working with Liferay I can imagine situations where it would be more or less reasonable, but it is not here and will not be most of the times.

    So, what should you do? You should submit your form to an action URL. To do it, first include the portlet taglib in your JSP:

    <%@ taglib uri="http://java.sun.com/portlet" prefix="portlet" %>
    

    Now, replace the action of your form by the <portlet:actionURL />. This tag will be replaced by a special URL generated by the portal. Also, precede each input name with the tag <portlet:namespace />; your <input type="text" name="login"> should become <input type="text" name="<portlet:namespace />login"> then. This tag will be replaced by a string which is associated with only your portlet; since you can have a lot of portlets in a page, each input should specify from what portlet it comes from. This is the final result:

    <form action="<portlet:actionURL />" method="post">
        <h1>Please Login</h1>
        Login:    <input type="text" name="<portlet:namespace />login"><br>
        Password: <input type="password" name="<portlet:namespace />password"><br>
        <input type=submit value="Login">
    </form>
    

    Now you are going to submit your data correctly – but how to get the submitted data? It certainly is not necessary to use a servlet! Instead, add to your custom portlet class a method called processAction(). This method should return void and receive two parameters, of the time javax.portlet.ActionRequest and javax.portlet.ActionResponse. This is an example of an empty processAction():

    public void processAction(ActionRequest request, ActionResponse response) {
        // Nothing to be done for now.
    }
    

    When a request to an action URL (as the one generated by <portlet:actionURL />) is sent to the server, it is firstly processed by the processAction() method and then by doView(). Therefore, the code you would write in your servlet should be put in your processAction(). The result should be then:

    public void processAction(ActionRequest request, ActionResponse response) {
        String name = (String)request.getParameter("login");
        System.out.println("The Name is "+name);
    }
    

    Try it and you will see that it will work well.

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

Sidebar

Related Questions

Ok before you think Not another question like this please read this first. I
Using Dozer to map two objects, I have: /** /* This first class uses
#include <iostream> using namespace std; // This first class contains a vector and a
Code first: '''this is main structure of my program''' from twisted.web import http from
This first block of code works as expected. It's a foreach to print values
EDITED: this first version was a false example with false assumptions! See below for
I have a MySQL table which contains comma-separated values like this: first row=(3,56,78,12) second
First this IS a Java question so forgive this first C#-related explanation... I've most
Please read this first. How do I make a button invisible just after click?
Inside of this first step towards a bootstrapped scheme interpreter I find the following

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.