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 8390401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:58:34+00:00 2026-06-09T18:58:34+00:00

I am creating a jsp page to test a validator servlet for a uni

  • 0

I am creating a jsp page to test a validator servlet for a uni assessment.

I am new to jsp so I just want to know how to make sure the field is empty on the first page load.

The idea is that when the form is submitted it is sent to a servlet that checks if the fields are empty or not (they have value entered by the user) and redirects them back to the form with error messages, if they are empty.

So here is a snippet of what my jsp fields look like:

<td class="formlabel">Name:</td>
<td><input type="text" size="27" id="name" name="name" value="<%= session.getAttribute("name")%>" /></td>

<%
if((String)session.getAttribute("name") == "") {
%>
    <span class="error">No name entered</span>
<%
}
%>

but currently the problem I am getting is that the session attribute is null. So null comes up in the input field. I don’t want this for the first jsp load, I just want it to be blank. How do I do this?

  • 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-09T18:58:36+00:00Added an answer on June 9, 2026 at 6:58 pm

    You can check the value by simply breaking:
    value="<%= session.getAttribute("name")%>
    into into a few statements:

    <%= String name = session.getAttribute("name");
        if(name == null) name = "";    
    %>value="<%=name%>
    

    But in general, instead of validating many fields, I would suggest adding another hidden input parameter to the form with id=”submitted” and value=”Y”:

    <input type="hidden id="submitted" name="submitted" value="Y">
    

    then add a line that checks for this POST/GET parameter:

    String submitted = request.getParameter("submitted");
    

    and change the if condition to:

     <%if((String)session.getAttribute("name") == "" && "Y".equals(submitted)){%>
    

    Remark:
    String comparison (in Java) should be done using equals() – not with ==

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

Sidebar

Related Questions

I am creating one application in which i am using jsp/servlet.. I want to
I am creating a jsp page where a single news item is shown, just
I want to create a JSP page or servlet that will work in 2
I am having a JSP page, where i am dynamically creating a Table data.
I am creating one jsp page in which I read in a text file,
I am creating a project in struts2 I have created a Registration.jsp page like
I am creating .jsp page and reiceve error about it ; String energyv=; int
I am creating a page in JSP where I have a dropdown list and
I am creating a JSP page, I get data from database this data is
<%@taglib uri=http://jakarta.apache.org/struts/tags-html prefix=html%> <%@taglib uri=http://jakarta.apache.org/struts/tags-bean prefix=bean %> I'm creating jsp file in eclipse it

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.