标签: jstl

如何使用<fmt:setLocale>为JSP设置语言环境?

我正在尝试在JSP中设置本地.

我以为我能做的事情如下:

<fmt:setLocale value="${param['local']}" scope="session"/>
Run Code Online (Sandbox Code Playgroud)

关于这个主题的Java自己的页面似乎说得非常多.

但是,当我去执行它时,我得到:

HTTP Status 500 -

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: /pages/ResourceBundlesJSTL.jsp(11,0) According to TLD or attribute directive in tag file, attribute value does not accept any expressions
 org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
 org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
 org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:148)
 org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:1232)
 org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:868)
 org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1539)
 org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
 org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2428)
 org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2434)
 org.apache.jasper.compiler.Node$Root.accept(Node.java:475)
 org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2376)
 org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1787)
 org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:211)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:360)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:340)
 org.apache.jasper.compiler.Compiler.compile(Compiler.java:327)
 org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594)
 org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:316)
 org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
 org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
 javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
note The full stack trace of the root cause …
Run Code Online (Sandbox Code Playgroud)

jsp locale jstl setlocale

0
推荐指数
1
解决办法
5671
查看次数

当JSTL escapeXml为false时,如何防止JavaScript注入(XSS)

我有一个人们可以添加他们的东西的表格.但是,在这种形式中,如果他们输入JavaScript而不是文本,他们可以轻松地注入他们想做的任何事情.为了防止它,我可以将escapeXml设置为true,但是普通的HTML也会被转义.

<td><c:out value="${item.textValue}" escapeXml="true" /></td>
Run Code Online (Sandbox Code Playgroud)

有没有其他方法来阻止JavaScript注入而不是将其设置为true?

javascript xss jsp jstl

0
推荐指数
1
解决办法
7948
查看次数

每个jsf的C都不起作用.JSF

我试图在jsf 2.0中使用带有hashmap或table的c foreach但是它没有工作所以我写了一个这样的简单代码仍然这个不工作....请帮助我失踪的地方...

<body>
<f:view>
    <c:forEach var="i" begin="1" end="20" step="1" varStatus ="status">
        <c:out value="#{i}" /> 
    </c:forEach>
</f:view>
Run Code Online (Sandbox Code Playgroud)

和输出为此我得到这样的..

#{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} #{i} 
Run Code Online (Sandbox Code Playgroud)

java jsf jstl

0
推荐指数
1
解决办法
6398
查看次数

使用JSTL的格式编号,没有舍入

我需要使用<fmt:formatNumber/>jstl标签格式化数字.输出应限制在小数点后3位,但不允许舍入,因此使用该属性maxFractionDigits="3"是不合适的,因为它会使数字四舍五入.

你有什么建议吗?

java jstl number-formatting

0
推荐指数
1
解决办法
6920
查看次数

从JSTL代码中设置javascript中的数组值

我有一个如下所示的代码:

在AnalyzeUserClient.jsp中:

<c:set var="arrayList"><%= (ArrayList<String>)request.getSession().getAttribute("arrayList") %></c:set>
var sessionId = [];
<c:forEach items=${arrayList} var="id">
sessionId.push("${id}"); // add them one at a time, assuming string values
</c:forEach>
Run Code Online (Sandbox Code Playgroud)

但是,这一行:

    sessionId.push("${id}");
Run Code Online (Sandbox Code Playgroud)

似乎没有将值传递给数组"sessionId"(我在浏览器上查看了源代码).所以问题是,我该怎么做才能将值传递给数组?

编辑:我刚刚意识到存在一些问题,因为JSTL是服务器端而JavaScript是客户端.所以它有解决方法吗?

javascript jsp jstl

0
推荐指数
1
解决办法
1万
查看次数

如果是jspl页面中的jstl标签中的其他内容

<div align="right">
     <b> Connected:</b> <%=(String)session.getAttribute("CONNECTION_DBNAME")%>
     </div>
Run Code Online (Sandbox Code Playgroud)
  • 我在jsp页面中有上面的代码
  • 最初会话CONNECTION_DBNAME没有值.
  • 当CONNECTION_DBNAME为null时,我需要显示未连接
  • 当CONNECTION_DBNAME具有值时,将打印一些值.
  • 我知道可以通过使用if else和条件来实现,但我不知道如何在jstl标签中使用if else.

javascript session jsp jstl

0
推荐指数
1
解决办法
5705
查看次数

JSTL - 遍历随机整数数组 - 不在webPage中显示

我正在尝试使用JSP/JSTL迭代随机生成的整数的myList(数组).生成和存储整数的代码snipet位于我的servlet中.

另一方面,遍历字符串的数组列表(参见下面的代码)可以很好地工作,但是当我使用基于相同逻辑的数组进行迭代时,我的网页只显示任何无序的随机整数列表.

谢谢你帮助我

我的Servlet

package be.intec.servlets;

    import java.io.IOException;
    import java.math.BigDecimal;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.LinkedHashMap;
    import java.util.List;
    import java.util.Map;

    import javax.servlet.RequestDispatcher;
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import be.intecbrussel.entities.Auto;

    @WebServlet("/JSTLServlet")
    public class JSTLServlet extends HttpServlet {

        private static final long serialVersionUID = 1L;

        private static final String VIEW = "WEB-INF/JSP/JSTL.jsp";

        protected void doGet(HttpServletRequest request,
                HttpServletResponse response) throws ServletException, IOException {

            RequestDispatcher dispatcher = request.getRequestDispatcher(VIEW);

            //=======below is the code using Array=====================================
            int[] myList = new int[42]; …
Run Code Online (Sandbox Code Playgroud)

java jsp servlets jstl

0
推荐指数
1
解决办法
5871
查看次数

将 out.println 转换为 c:out

JSTL c:out这是什么版本JSP

<% 

 PersonController personController = new PersonController();
 personController.populate();
 out.println(personController.getAllPeople().get(0).getName()); 

%>
Run Code Online (Sandbox Code Playgroud)

其背后运行的代码:

PersonController

List<Person> allPeople = new ArrayList<Person>();

public void populate() {
  Person person = new Person();
  person.setName("Jeff");
  allPeople.add(person);
}

public List<Person> getAllPeople() {
    return allPeople;
}

public void setAllPeople(List<Person> allPeople) {
    this.allPeople = allPeople;
}
Run Code Online (Sandbox Code Playgroud)

Person

private String name;

public String getName() {
   return name;
}

public void setName(String name) {
    this.name = name;
}
Run Code Online (Sandbox Code Playgroud)

java jsp jstl

0
推荐指数
1
解决办法
530
查看次数

将列表发送到jsp标记

我想发送list元素(位于我的JSP上):

${mylist}
Run Code Online (Sandbox Code Playgroud)

对于我的自定义标签mytag.tag,这是我在JSP页面中的内容:

<tags:mytag list="${mylist}" ></tagsmytag>
Run Code Online (Sandbox Code Playgroud)

但是当我这样发送它时,我无法访问它的元素,这里是mytag.tag:

<%@ taglib uri="http://www.springframework.org/tags/form" prefix="springForm"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@attribute name="list" required="true"%>

<c:forEach items="${pageScope.list}"  var="listVar">
    <option value="${listVart[0]}">${listVar[1]}</option>
</c:forEach>
Run Code Online (Sandbox Code Playgroud)

后端控制器:

@ModelAttribute("mylist")
List<Permission> getAllActivePermissions(){
    return permissionService.getAllActivePermissions();
}
Run Code Online (Sandbox Code Playgroud)

例外是:

javax.el.PropertyNotFoundException: Property '0' not found on type java.lang.String
at javax.el.BeanELResolver$BeanProperties.get(BeanELResolver.java:237)
at javax.el.BeanELResolver$BeanProperties.access$400(BeanELResolver.java:214)
at javax.el.BeanELResolver.property(BeanELResolver.java:325)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:85)
at org.apache.jasper.el.JasperELResolver.getValue(JasperELResolver.java:104)
at org.apache.el.parser.AstValue.getValue(AstValue.java:183)
at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:185)
at org.apache.jasper.runtime.PageContextImpl.proprietaryEvaluate(PageContextImpl.java:1026)
at org.apache.jsp.tag.webmultiple_tag._jspx_meth_c_005fforEach_005f1(webmultiple_tag.java:454)
at org.apache.jsp.tag.webmultiple_tag._jspx_meth_springForm_005fselect_005f1(webmultiple_tag.java:413)
at org.apache.jsp.tag.webmultiple_tag._jspx_meth_c_005fotherwise_005f0(webmultiple_tag.java:375)
at org.apache.jsp.tag.webmultiple_tag.doTag(webmultiple_tag.java:222)
at org.apache.jsp.WEB_002dINF.pages.roles.newRole_jsp._jspx_meth_tags_005fmultiple_005f0(newRole_jsp.java:674)
at org.apache.jsp.WEB_002dINF.pages.roles.newRole_jsp._jspx_meth_springForm_005fform_005f0(newRole_jsp.java:566)
at org.apache.jsp.WEB_002dINF.pages.roles.newRole_jsp._jspService(newRole_jsp.java:378)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:432) …
Run Code Online (Sandbox Code Playgroud)

java tags spring jsp jstl

0
推荐指数
1
解决办法
1160
查看次数

列表值是打印地址而不是值

我有下面的DAO文件.

package org.DAO;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;

import org.bean.UserBean;
import org.code.general.DBConnection;

public class GetDataDAO {
    DBConnection dbConnection = new DBConnection();

    public List<UserBean> list() throws Exception {
        List<UserBean> userBeans = new ArrayList<UserBean>();
        try {
            Connection conn = dbConnection.conn;
            Statement stmt = dbConnection.stmt;
            ResultSet rs = dbConnection.rs;
            PreparedStatement ps = dbConnection.ps;
            String excelPath = dbConnection.excelPath;
            String queryString = null;
            dbConnection.createClassForName();
            conn = DriverManager.getConnection(
                    "jdbc:odbc:Driver={Microsoft Excel Driver (*.xls)};DBQ=" + …
Run Code Online (Sandbox Code Playgroud)

java jstl

0
推荐指数
1
解决办法
627
查看次数

如何在jsp中显示从dao获得的数据

在jsp中

<table width="100%" id='table1'  border="0" cellspacing="2" cellpadding="2">
    <tr class="tab-highlighted-2">
        <td class="tab-highlighted-2" width="10%">
          <div align="left">Project ID</div>
        </td>
        <td class="tab-highlighted-2" width="10%">
          <div align="left">Project Name</div>
        </td>
        <td class="tab-highlighted-2" width="20%">
          <div align="left">Cost Center</div>
        </td>
        <td class="tab-highlighted-2" width="20%">
          <div align="left">Manager</div>
        </td>
    </tr>
  <tr class="bg-row1">
  <c:forEach items="${resultList}" var="resultList"> 
        <td class="td-highlighted-2">
         <div align="left"><a href="UpdateProject.html">${resultList.Projid}</a></div>
        </td>
        <td class="td-highlighted-2">
          <div align="left">${resultList.Projname}</div>
        </td>
        <td class="td-highlighted-2">
          <div align="left">${resultList.Cost}</div>
        </td>
        <td class="td-highlighted-2">
          <div align="left">${resultList.Manager}</div>
        </td>  
    </tr>  
    </table> 
Run Code Online (Sandbox Code Playgroud)

在道

public final class SearchProjDAO   
{ 
    private static InitialContext context;  
    String CLASS_NAME="DBConnectionFactory";  

    public ArrayList  submitProjectDetails(SearchProjVO …
Run Code Online (Sandbox Code Playgroud)

java jsp jstl

-1
推荐指数
1
解决办法
3768
查看次数

使用jstl使用for循环模拟while循环

我有这段代码如下

     while(children.hasNext())
            {
                Page child1=children.next();
            }
Run Code Online (Sandbox Code Playgroud)

我需要使用for循环或每个循环在我的jstl中使用此代码.

我可以知道我们该怎么做吗?

java iterator for-loop jstl java-ee

-1
推荐指数
1
解决办法
4613
查看次数

为什么$ {flag == Y}返回True,而$ {flag =='Y'}返回False?

我对以下行为感到困惑。变量标志从控制器传递到jsp代码:

flag: <c:out value="${requestScope.flag}"/> 
flag eq 'Y': ${requestScope.flag eq 'Y'}
flag == 'Y': ${requestScope.flag=='Y'}
flag==Y: ${requestScope.flag==Y}
Run Code Online (Sandbox Code Playgroud)

情况1:标志未传递到视图(输出):

flag: 
flag eq 'Y': false 
flag == 'Y': false 
flag==Y: true
Run Code Online (Sandbox Code Playgroud)

情况2:将值“ Y”的标志传递给视图:

flag: Y
flag eq 'Y': true 
flag == 'Y': true 
flag==Y: false
Run Code Online (Sandbox Code Playgroud)

java jsp servlets jstl undefined

-1
推荐指数
1
解决办法
69
查看次数