java标准i o重定向,Eclipse中的I / O重定向?

Is it possible to use I/O redirection in Eclipse?

I want to redirect standard input/output on the command line like java MyProgram output.txt, but I can't seem to get it to work in Eclipse. I tried including the

解决方案

To truly redirect both, the simplest way is still to define your program as an external script

"java %1 %2 %3 %4 < %5 > %6"

(adapt the number of parameters to your particular program)

In the Run menu, click 'External Tools.../Open External Tools Dialog" and define an external launch configuration in which you will specify both the arguments and the input and output file.

It is not an ideal solution though, as you cannot debug directly your code (with a "debug" launcher configuration).

Instead you have to remote debug it (add '-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000' in your generic Java launcher script)

Once you have launched your external tool, launch a remote debug session through the "debug launcher 'Remote Java Application'" section:

4pViB.jpg

Eclipse 实现登录验证可以使用请求转发和重定向两种方式。其,请求转发是指将请求转发给另一个资源进行处理,而重定向是指将请求重定向到另一个资源进行处理。 使用请求转发的方式,可以将用户提交的登录信息传递给后台进行验证,如果验证通过,则将用户重定向到主页;如果验证不通过,则将用户重定向到登录页面重新输入信息。示例代码如下: ```java // 登录验证 if (username.equals("admin") && password.equals("123456")) { // 验证通过,将用户信息存入 session HttpSession session = request.getSession(); session.setAttribute("username", username); // 转发到主页 RequestDispatcher dispatcher = request.getRequestDispatcher("/index.jsp"); dispatcher.forward(request, response); } else { // 验证不通过,重定向到登录页面 response.sendRedirect(request.getContextPath() + "/login.jsp"); } ``` 使用重定向的方式,可以将用户提交的登录信息传递给后台进行验证,如果验证通过,则将用户重定向到主页;如果验证不通过,则将用户重定向到登录页面重新输入信息。示例代码如下: ```java // 登录验证 if (username.equals("admin") && password.equals("123456")) { // 验证通过,将用户信息存入 session HttpSession session = request.getSession(); session.setAttribute("username", username); // 重定向到主页 response.sendRedirect(request.getContextPath() + "/index.jsp"); } else { // 验证不通过,重定向到登录页面 response.sendRedirect(request.getContextPath() + "/login.jsp"); } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值