小编Jos*_*des的帖子

如何使用iText和Java检查具有相同变量名称的PDF文件中的复选框

我一直在使用iTextJava来自动填写PDF文档.我做的第一件事是映射每个领域.一旦我将每个字段映射,我将变量名称保存Strings到易于访问.

到现在为止还挺好.问题是我有一组6个具有相同变量名称的复选框.例如,他们被命名topmostSubform[0].Page2[0].p2_cb01[0].

通过一些测试,我可以弄清楚,如果我检查第一个复选框,那么 topmostSubform[0].Page2[0].p2_cb01[0] = 1

如果我检查第二个(自动取消选中第一个),那么 topmostSubform[0].Page2[0].p2_cb01[0] = 2

然后topmostSubform[0].Page2[0].p2_cb01[0] = 3连续获得6最后一个数字.

form.setField("topmostSubform[0].Page2[0].p2_cb01[0]", "1");用来填补田地.当我填写该值时1,第一个复选框被选中,但当我填写2应检查第二个复选框的数字时,它不起作用.如果我选择2, 3, 4, 5 or 6它只是不起作用并不重要,复选框保持空白我无法检查它们.

这里有一段代码:

String _5_1 = "topmostSubform[0].Page2[0].p2_cb01[0]";

AcroFields form = stamper.getAcroFields();

form.setField(_5_1, "3");
Run Code Online (Sandbox Code Playgroud)

拜托,我需要建议.

java pdf itext

6
推荐指数
1
解决办法
1952
查看次数

将java.util.Calendar ISO 8601格式转换为java.sql.Timestamp

我有ISO 8601日期格式的日期2015-09-08T01:55:28Z.我使用此代码将ISO 8601命运转换为Calendar对象:

Calendar cal = javax.xml.bind.DatatypeConverter.parseDateTime("2015-09-08T01:55:28Z");
Run Code Online (Sandbox Code Playgroud)

现在我需要使用它cal.getTime()来获取我的时间,但我需要将其转换为java.sql.Timestamp.我试着这样做:

final Timestamp finalDate = (Timestamp) cal.getTime();
Run Code Online (Sandbox Code Playgroud)

但是我收到了这个错误:

java.lang.ClassCastException: java.util.Date cannot be cast to java.sql.Timestamp
Run Code Online (Sandbox Code Playgroud)

想法?

java timestamp calendar

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

使用依赖于Spring Security的JUnit测试Spring Controller

我有一个Spring应用程序,我正在构建JUnit测试来测试某个Controller.

问题是Controller我在里面调用这段代码:

final Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
final String userName = authentication.getName();
Run Code Online (Sandbox Code Playgroud)

换句话说,我需要在调用之前进行身份验证Controller.我JUnit用这段代码写了一个测试:

private MockMvc mockMvc;

    @Test
    public void getPageTest() throws Exception{
        final ProcessFileController controller = new ProcessFileController();
        mockMvc = standaloneSetup(controller).build();

    mockMvc.perform(get(URI.create("/processFile.html")).sessionAttr("freeTrialEmailAddress", "")).andExpect(view().name("processFile"));
        }
Run Code Online (Sandbox Code Playgroud)

当我跑的时候给了我一个NullPointerException权利,final String userName = authentication.getName();因为我authenticationnull因为我没有登录.

问题是:有没有办法模拟身份验证?欢迎所有想法.

谢谢.

java junit spring spring-mvc spring-security

4
推荐指数
1
解决办法
1917
查看次数

使用Angular JS和Spring MVC提交表单

我是Angular JS的noob,我很难使用Angular JS和Spring MVC提交一个简单的Form.我收到此错误:

请求的资源不可用

mock.jsp

<%@taglib prefix='c' uri='http://java.sun.com/jsp/jstl/core'%>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@taglib prefix="security"uri="http://www.springframework.org/security/tags" %>
<!doctype html>
<html>
<head>
<title>Settings</title>
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/workflow.css">
<link rel="stylesheet" href="css/upload.css">
<link rel="stylesheet" href="css/jquery.qtip.min.css">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css"> 
<link rel="shortcut icon" href="images/logo-small.png" />

</head>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
<script type="text/javascript">
    var app = angular.module('formSubmit', []);

    app.controller('FormSubmitController',[ '$scope', '$http', function($scope, $http) {

        $scope.list = [];
            $scope.headerText = 'AngularJS Post Form Spring MVC example: Submit below form';
            $scope.submit = function() {

                var formData = …
Run Code Online (Sandbox Code Playgroud)

java forms spring-mvc angularjs angularjs-forms

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