If you are someone who suffers with celiac sprue (gluten allergy) then yes, you need to avoid products containing gluten. If you have an ulcer due to Helicobacter pylori infection
then you will need to heal up with treatment and time. Assuming you have had an endoscopy
. Be sure to discuss with your gastroenterologist.