小编Tin*_*iny的帖子

如何在JSP中检索当前页面名称?

JSP中有没有办法知道当前页面名称(而不是整个URL或URI)?当然,我们可以执行以下操作来检索JSP中的当前页面名称.

String servletPath=request.getServletPath();
out.println(servletPath.substring(servletPath.lastIndexOf("/")+1, servletPath.length()));
Run Code Online (Sandbox Code Playgroud)

这可以检索当前页面名称(可能是我按照错误的方式这样做).在JSP中有一个公平而直接的方法来检索当前页面名称吗?

[此外,/此方法中的分隔符servletPath.lastIndexOf("/")应始终独立于任何操作系统支持的任何文件系统].

java jsp java-ee

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

哪个数据类型用于在Oracle 10g中存储DateTime?

在Oracle 10g数据库中使用哪种数据类型来存储日期时间(不仅是日期而且还有时间)?我已经阅读了一些内容(可能是错误的)" Oracle 10g中的日期数据类型可以存储日期时间 "但是当我尝试这样做时似乎没有发生.

DATE数据类型是datetime数据类型.它存储日期和时间.日期部分基于公元前4712年1月1日以来的天数.时间部分基于自午夜以来的秒数.链接

我通过Java作为前端尝试使用以下SQL直接在Oracle终端上.

insert into discount 
values(7, 'Code', 12.5, to_date('11-AUG-2012 06:05:23', 'dd-mon-yyyy hh:mi:ss'), 
to_date('20-AUG-2012 07:50:23', 'dd-mon-yyyy hh:mi:ss'))
Run Code Online (Sandbox Code Playgroud)

它可以工作,但(在这两种情况下)Oracle只是忽略时间部分并只插入SQL中指定的日期而没有任何错误?

哪个数据类型用于在Oracle 10g中存储日期时间?是TimeStamp吗?

java oracle oracle10g

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

在Java中输入类型

可能重复:
我知道为什么需要在这里将整数文字转换为(int)?

package typecastingpkg;

public class Main
{        
    public static void main(String[] args)
    {
       byte a=10;
       Integer b=(int)-a;
       System.out.println(b);

       int x=25;
       Integer c=(Integer)(-x); // If the pair of brackets around -x are dropped, a compile-time error is issued - illegal start of type.
       System.out.println(c);

       Integer d=(int)-a;     //Compiles fine. Why does this not require a pair of braces around -a?
       System.out.println(d);
    }
}
Run Code Online (Sandbox Code Playgroud)

在此代码中,在将-x基本类型int转换为包装类型时Integer,会产生编译时错误:illegal start of type.

Integer c=(Integer)-x;
Run Code Online (Sandbox Code Playgroud)

它需要一对大括号周围的-xInteger …

java casting compiler-errors type-conversion

8
推荐指数
2
解决办法
2896
查看次数

Varargs在Java中使用null参数

以下代码仅使用空引用作为varargs参数.

package currenttime;

import java.util.Arrays;

public class Main
{
    private static void temp(String...str)
    {
        System.out.println(Arrays.asList(str));
    }

    public static void main(String[] args)
    {
        temp(null,null);
        temp(null);
    }
}
Run Code Online (Sandbox Code Playgroud)

第一次调用方法temp(null, null);显示[null, null]意味着str[0]=nullstr[1]=null.

但是后来的召唤temp(null);导致NullPointerException抛出它str本身就是这样null.

如果它的类型转换为String类似的东西temp((String)null);,它可以工作和显示[null].

为什么在最后一次调用中,需要显式类型转换?在我看来,它被认为是一个字符串数组,其null引用与第一次调用不同.什么是正确的答案?

java variadic-functions

8
推荐指数
1
解决办法
5269
查看次数

JavaScript中的自动类型转换

JavaScript中的以下所有表达式都非常明显.

var x = 10 + 10;
Run Code Online (Sandbox Code Playgroud)

价值x20.

x = 10 + '10';
Run Code Online (Sandbox Code Playgroud)

x在这种情况下的值是1010因为+运算符过载.如果任何操作数是string类型,则进行字符串连接,如果所有操作数都是数字,则执行加法.

x = 10 - 10;
x = 10 - '10';
Run Code Online (Sandbox Code Playgroud)

在这两种情况下,值x都是0因为-操作符没有以这种方式重载并且所有操作数都转换为数字,如果它们不是在执行实际减法之前(你可能会澄清,如果我错了) .


以下表达式会发生什么.

x = '100' - -'150';    
Run Code Online (Sandbox Code Playgroud)

价值x250.这似乎也是显而易见的,但这个表达看起来有点像下面的表达式.

x = '100' +'150';
Run Code Online (Sandbox Code Playgroud)

如果是这种情况,则这两个字符串将被连接并分配100150x.那么为什么在这种情况下进行添加呢?


编辑:

+'10' + 5返回15'a' + + 'b'返回aNaN.有谁知道为什么?

javascript

8
推荐指数
1
解决办法
2913
查看次数

java.lang.AbstractMethodError:oracle.jdbc.driver.T4CPreparedStatement.setCharacterStream(ILjava/io/Reader; J)V

尝试将CKEditor(用于CMS - 内容管理系统)的内容插入Oracle数据库 - Oracle 10g时,我遇到以下异常.

Oracle表中的字段是clob类型.

java.lang.AbstractMethodError:oracle.jdbc.driver.T4CPreparedStatement.setCharacterStream(ILjava/io/Reader; J)V

另一方面是当我尝试使用JSON通过AJAX将相同的内容插入数据库时​​,不会导致此异常.

我正在使用

  • 春季3.2.0
  • Hibernate 4.2.0.CR1
  • Oracle JDBC驱动程序版本 - 10.2.0.5.0
  • JDK - 1.7
  • Oracle 10g

由于我将Hibernate从3.2.5更改为4.2.0.CR1,因此导致异常

这个链接说

setCharacterStream()方法有3个版本,其中两个是作为JDBC 4.0(Java 1.6)的一部分添加的.您的JDBC驱动程序可能不支持它们:

这个答案建议升级JDBC驱动程序,但这个问题是关于我还没有使用的Oracle 11g.

我不太确定.JDBC 11.x驱动程序是否与Oracle 10g兼容?曾几何时,我曾试过一个,但它没有正常工作.

如何解决这个异常?


编辑:

我刚刚下载了 ojdbc6.jar(之前是ojdbc14.jar上面指定的驱动程序),其中包含Oracle JDBC Driver version - "11.1.0.7.0-Production".

异常异常消失了.请告诉我,如果此驱动程序版本与Oracle 10g完全兼容.

spring hibernate clob oracle10g

8
推荐指数
1
解决办法
9233
查看次数

将图片添加到Excel单元格时,Apache POI-HSSF会扭曲图像大小

我正在使用Apache POI-HSSF将图片添加到单元格中.图像是120x100,但无论我做什么以及如何调整它,Excel电子表格总是显示它跨越多行并将其扭曲到比宽度更大的高度.

如何保持原始尺寸?

我的代码:

InputStream is = new FileInputStream(getImageURL());
byte[] bytes = IOUtils.toByteArray(is);
int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
is.close();

//add a picture shape
CreationHelper helper = wb.getCreationHelper();
ClientAnchor anchor = helper.createClientAnchor();
// Create the drawing patriarch.  This is the top level container for all shapes.
Drawing drawing = sheet1.createDrawingPatriarch();
//set top-left corner of the picture,
//subsequent call of Picture#resize() will operate relative to it

anchor.setAnchorType(0);
anchor.setCol1(1);
anchor.setRow1(1);

Picture pict = drawing.createPicture(anchor, pictureIdx);

//auto-size picture relative to its top-left corner
pict.resize(); …
Run Code Online (Sandbox Code Playgroud)

java excel image hssf apache-poi

8
推荐指数
2
解决办法
8442
查看次数

通过Ajax更新JSF组件后,JavaScript/jQuery事件侦听器不起作用

我正在<p:dataTable>filter(其id为id)上执行以下jQuery函数,该函数允许用户仅输入过滤器组件中的数字.

$(document).ready(function() {
    $("#form\\:dataTable\\:id\\:filter").keydown(function(event) {
        //Allow: tab, escape, and enter
        if(event.keyCode===9||event.keyCode===27||event.keyCode===13||
            //Allow: Ctrl+A, Ctrl+C
            (event.keyCode===65&&event.ctrlKey===true)||(event.keyCode===67&&event.ctrlKey===true)||
            //Allow: home, end, left, right
            (event.keyCode>=35&&event.keyCode<=39)){
            //let it happen, don't do anything
            event.preventCapture();
            return;
        }//backspace, delete
        else if(event.keyCode===46||event.keyCode===8)
        {
            return;
        }
        else{//Ensure that it is a number and stop the keypress
            if (event.shiftKey||(event.keyCode<48||event.keyCode>57)&&(event.keyCode< 96||event.keyCode>105)){
                //event.preventDefault();
                event.preventCapture();
            }
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

此功能位于context/resources/default/js/digit_only_textfield.js.因此,它可以在XHTML页面上使用,如,

<h:outputScript library="default" name="js/digit_only_textfield.js"/>
Run Code Online (Sandbox Code Playgroud)

XHTML页面如下所示.

<h:outputScript library="default" name="js/digit_only_textfield.js"/>

<h:form id="form" prependId="true">

    <!--PrimeFaces extension <pe:blockUI>-->         

    <p:remoteCommand name="updateTable" update="dataTable"/>

    <p:panel id="panel"> …
Run Code Online (Sandbox Code Playgroud)

javascript jquery jsf primefaces jsf-2.2

8
推荐指数
1
解决办法
6144
查看次数

使请求参数绑定不区分大小写

我有一个要求,即使param名称的情况发生变化,我必须使requestParams正确绑定.注意:我使用的是spring 3.2

例如:http://localhost:8080/sample/home?**userName**= xxx或http://localhost:8080/sample/home?username = xxx或 http://localhost:8080/sample/home?usernaMe = xxx应正确映射到我的@RequestParam值.

@RequestMapping(value = "home", method = RequestMethod.GET)
public goToHome(@RequestParam(value = "userName", required = false) String userName) {

}
Run Code Online (Sandbox Code Playgroud)

所有三个URL都应该调用上面的方法并正确绑定用户名.请给我一些关于如何通过实现新的参数处理程序解析器来实现它的建议?一般来说,覆盖spring配置类比改变所有@RequestParam的代码中的逻辑更受欢迎.

java spring spring-mvc

8
推荐指数
1
解决办法
9544
查看次数

重置子p:selectOneMenus在ap:dataTable中为空,当选择其父列表中的标签项时

在MySQL数据库中有三个表category,sub_categorybrand(制造商)其中category是其余的父,即sub_categorybrand.我希望,菜单之间的关系可以根据表关系更清晰.

所有三个<p:selectOneMenu>都被放置<p:dataTable>在三个相应的列中,如下所示<p:column>.我忽略<p:column>,<p:cellEditor>,<f:facet name="output">,<f:facet name="input">,<p:rowEditor>和所有这些滋扰赘述.

row对应于这是一个JPA管理实体product在这种情况下,通过指定var="row"<p:dataTable>关联的.

这是实际的问号:当一个项目(第一个)null的值categoryList被选择(母公司),其子清单subCategoryListbrandList应该休息了个空.

分类清单:

<p:selectOneMenu id="categoryList"
                 value="#{row.category}"
                 required="#{param['javax.faces.source'] ne component.clientId}">

    <f:selectItem itemLabel="Select"
                  itemValue="#{null}"/>
    <!-- When this item is selected, its children below should be reset to empty. -->

    <f:selectItems var="category"
                   value="#{productManagedBean.categories}"
                   itemLabel="Select"
                   itemValue="#{category}"/> …
Run Code Online (Sandbox Code Playgroud)

jsf selectonemenu primefaces

8
推荐指数
1
解决办法
411
查看次数