0

i want create array in JSP

<?php
$lang = array();
$lang['PAGE_TITLE'] = 'My website page title';
$lang['HEADER_TITLE'] = 'My website header title';
$lang['SITE_NAME'] = 'My Website';
$lang['SLOGAN'] = 'My slogan here';
$lang['HEADING'] = 'My Heading';
echo $lang['SITE_NAME']; // print words "My Website"
?>

i try in JSP like this.

<%
String[] lang;
lang["PAGE_TITLE"] = "My website page title";
lang["HEADER_TITLE"] = "My website header title";
lang["SITE_NAME"] = "My Website";
lang["SLOGAN"] = "My slogan here";
lang["HEADING"] = "My Heading";
out.println(lang["SITE_NAME"]);  // print words "My Website"
%>

this error, cannot convert int to string Help me thank's, i want call Array JSP like code Array in PHP

1
  • What exactly is the problem? Commented Feb 18, 2016 at 3:50

1 Answer 1

3

I think you should use Map<String,String> same as:

Map<String, String> lang = new HashMap<String, String>();
lang.put("PAGE_TITLE", "My website page title");
lang.put("HEADER_TITLE","My website header title");
lang.put("SITE_NAME","My Website");
lang.put("SLOGAN", "My slogan here");
lang.put("HEADING","My Heading");
out.println(lang.get("SITE_NAME"));
Sign up to request clarification or add additional context in comments.

2 Comments

An error occurred at line: 3 in the jsp file: learning.jsp Map cannot be resolved to a type 1: 2: <% 3: Map<String, String> lang = new HashMap<String, String>(); 4: lang.put("PAGE_TITLE", "My website page title"); 5: lang.put("HEADER_TITLE","My website header title"); 6: lang.put("SITE_NAME","My Website");
You just need to import java.util.*; for this

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.