dousu5608 2016-02-18 02:57
浏览 77
已采纳

将代码PHP数组转换为JSP

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条回答 默认 最新

  • duangong0690 2016-02-18 03:02
    关注

    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"));
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 如何把照片修复成原始拍摄图
  • ¥80 Exited too quickly (process log may have details)
  • ¥15 爬知乎登录之后内容加载不出来
  • ¥15 怎么用protues测量通频带
  • ¥15 zepelin使用sparkInterpreter 异常
  • ¥15 paho mqtt 接收不到消息
  • ¥15 函数r关于两个分量y,z方向上的图像,分开画r随y的图像,r随z的图像
  • ¥15 如何用Matlab求Pearcey函数的数值积分?
  • ¥15 一个简单的函数定义问题,输出结果是相反的,怎么回事呢?
  • ¥15 页面加载报错,不知道怎么处理