小编Tin*_*uar的帖子

如何在java中的另一个目录中打开文件?

如何打开当前目录中但不存在于另一个目录中的文件.例如,我有一个文件夹F:/ test,我的文件位于F:/test/test2/doit.txt和D:/ test3/doit2.文本

在制作File对象时在参数中输入的内容如下:

File f = new File("/test2/doit.txt");
Run Code Online (Sandbox Code Playgroud)

java directory file

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

在JSP页面中作为null接收的变量值

我做了一个简单的登录应用程序.但是每当发送表单时,servlet都会收到空数据.

以下是登录页面

<body>
<form action="login">
    Enter login Name : <input type="text" name="userName"/><br/>
    Enter password   : <input type="password" name="userPassword"/><br/>
    <input type="submit" value="Log In"/>
</form>
Run Code Online (Sandbox Code Playgroud)

以下是用于检查输入的变量值的servlet代码

@WebServlet("/login")
public class loginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#HttpServlet()
 */
public loginServlet() {
    super();
    // TODO Auto-generated constructor stub
}

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String name = (String)request.getAttribute("userName");
    String password = (String)request.getAttribute("userPassword");

    System.out.print("in doGet method");
    System.out.print(name+" "+password+" are these");


    if(name!=null && …
Run Code Online (Sandbox Code Playgroud)

java jsp servlets

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

如何在bootstrap中添加动态div?

我使用以下方法在点击"addButton"时添加多个div,如下面的小提琴所示:

http://jsfiddle.net/harshmadhani/jpb93/

$(document).ready(function () {
var counter = 2;
$("#addButton").click(function () {
        if (counter > 2) {
            alert("Only 2 textboxes allowed");
            return false;
        }
        $('<div/>',{'id':'TextBoxDiv' + counter}).html(
          $('<label/>').html( 'Textbox #' + counter + ' : ' )
        )
        .append( $('<input type="text">').attr({'id':'textbox' + counter,'name':'textbox' + counter}) )
        .appendTo( '#TextBoxesGroup' )       
        counter++;
    });

    $("#removeButton").click(function () {
        if (counter == 1) {
            alert("No more textbox to remove");
            return false;
        }
        counter--;
        $("#TextBoxDiv" + counter).remove();
    });
});
Run Code Online (Sandbox Code Playgroud)

我必须使用html添加文本并在其后添加.在Bootstrap中有没有其他方法可以解决这个问题?

jquery twitter-bootstrap

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

Injectmocks 无法实例化,因为找不到线程绑定请求

我正在尝试在 REST API 中创建一个日志记录实用程序,并且我需要来自 HttpServletRequest 的一些详细信息。

以下是日志记录实用程序的代码:

import javax.servlet.http.HttpServletRequest;

import org.springframework.context.annotation.Scope;
import org.springframework.context.annotation.ScopedProxyMode;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import lombok.Getter;
import lombok.Setter;

@Component
@Scope(scopeName = "session",proxyMode = ScopedProxyMode.TARGET_CLASS)
@Getter
@Setter
public class LoggingUtil {

    private String uri;
    private String callerIp;
    private String authorization;

    public LoggingUtil() {
        HttpServletRequest httpServletRequest = 
                ((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes()).getRequest();
        this.uri = httpServletRequest.getRequestURI();
        this.callerIp = httpServletRequest.getRemoteAddr();
        this.authorization = httpServletRequest.getHeader("Authorization");
    }

    public void log() {
        System.out.println("URI is "+this.uri+" Caller IP is "+this.callerIp+"authorization id is "+this.authorization);
    }
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用 JUnit-Mockito 框架对类进行单元测试,但测试覆盖率始终存在 …

java junit spring unit-testing spring-boot

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