所以我将我的java应用程序推送到服务器,非常兴奋.
现在我想测试一下,如何将发布的数据保存到我的servlet文件中,文件名应该是一个唯一的guid.
到目前为止我有这个:
public class TestServlet extends javax.servlet.http.HttpServlet {
protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException, IOException {
}
protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
throws javax.servlet.ServletException, IOException {
PrintWriter printWriter = response.getWriter();
printWriter.print("hello, world from testservlet!");
}
}
Run Code Online (Sandbox Code Playgroud)
因此,假设http发布数据(比如大约50K)将被发布到字段"有效负载",我如何获取发布的文本,并将其保存到文件中,文件名为GUID.
java有一个构造来清理一个打开的文件,比如在c#中:
using(var file = new ....)
{
// write to file
}
Run Code Online (Sandbox Code Playgroud)
这会关闭连接并清理内存等.
另外,我是否需要为tomcat设置特殊权限才能保存此文件?
我现在默认设置(只是在VPS上玩)使用ubuntu 11,安装tomcat6.
谢谢.
我有一个简单的servlet,如果它有一个查询参数'hello',我写一个文件,因为这是一个测试,我想在网页上也显示错误.
IntelliJ抱怨我没有捕获IOException,不知道出了什么问题:
private static void WriteToFile(String filePath, String fileName, String fileData) {
FileWriter writer = null;
try {
writer = new FileWriter(fileName);
writer.write(fileData);
} catch(IOException ex) {
} finally {
if(writer != null) {
writer.close();
}
}
}
Run Code Online (Sandbox Code Playgroud)
另外,在我的例外情况中,我注意到大多数人在网上写道:
如何将错误输出到网页?
我有一个非rails应用程序,我想使用rails active-record migrations.
我没有在任何问题之前做过这个,但这次我希望我能以某种方式获得AR迁移来生成现有数据库的迁移脚本,以便我可以从中构建.
这可能吗?
(对我来说唯一的其他解决方案是在迁移中重新创建整个数据库,如果有某种内置方式,我不想这样做).
我正在尝试使用嵌入式实例运行我的spring MVC.我发现了这个问题:Jetty Embedded Spring应用程序
我使用的是jetty版本:7.6.2.v20120308,javax servlet:2.5
我正在使用IntelliJ,类WebAppContext似乎没有解析为任何包/命名空间.这个类是存在还是被替换了?
import org.eclipse.jetty.server.Server;
public static void main(String[] args) throws Exception {
Server server = new Server(8080);
WebAppContext ????????
}
Run Code Online (Sandbox Code Playgroud) 我的班级目前看起来像:
class WebConfig(config: Config) {
def this() {
this(ConfigFactor.load())
}
def dbPort = config.getInt("mysql.port")
}
Run Code Online (Sandbox Code Playgroud)
我不喜欢当我调用 dbPort 时,它每次都必须调用然后强制转换配置。
所以我想创建私有字段并在构造函数中设置它们,然后调用 dbPort 将简单地返回私有字段的内容。
我怎样才能做到这一点?
我尝试创建一个私有变量,但收到此错误:
class WebConfig(config: Config) {
private var _dbPort: Int
def this() {
this(ConfigFactor.load())
_dbPort = config.getInt("mysql.port")
}
def dbPort: Int = _dbPort
}
Run Code Online (Sandbox Code Playgroud)
错误:
abstract member may not have private modifier
Run Code Online (Sandbox Code Playgroud) 我想编写一个简单的方法,将函数作为参数然后执行它.
def exec(f: (a:Int, b:Int) => Boolean): Boolean = f(a,b)
Run Code Online (Sandbox Code Playgroud)
我不确定上面有什么问题,但我收到错误:
<console>:1: error: ')' expected but ':' found.
Run Code Online (Sandbox Code Playgroud) 我刚学会了当列表为空时,EXISTS返回0.
我正在使用这个处理一个列表:
rpoplpush source target
Run Code Online (Sandbox Code Playgroud)
当我完成处理时,我仍然想看看source是否为空,但是如果密钥存在的话.但由于列表为空,因此返回0.
EXISTS source
(integer) 0
Run Code Online (Sandbox Code Playgroud)
有没有办法知道你的列表是空的,但密钥确实存在于redis中?
我想重定向到同一页面,但添加一些查询字符串值。
如果已经有一个querystring值,我想将其剥离并添加一个新的值。
我的代码当前无法正常工作,不确定为什么:
var url = window.location.href;
if(url.indexOf("?") > 0) {
url = url.substring(0, url.indexOf("?"));
} else {
url += "?joined=true";
}
window.location.replace(url);
Run Code Online (Sandbox Code Playgroud) 我在akka中称呼这个:
for {
products <- myActor ? MyActor.Search("...", 25)
} yield {
val model = MyModel(products)
}
Run Code Online (Sandbox Code Playgroud)
该MyModel(products)行有一个错误说预期Vector[Product],实际Any.
签名是这样的:
def search(searchText: String, hitsPerPage: Int): Vector[Product]
Run Code Online (Sandbox Code Playgroud)
为什么它会以Any类型返回?
found : Any
[error] required: Vector[com.example.Product]
Run Code Online (Sandbox Code Playgroud)
我需要投射回复吗?
我有一些用于API响应的控制器,但该应用程序的其余部分是常规的Rails 5应用程序。
如果我将基类更改为
ApplicationController::API
Run Code Online (Sandbox Code Playgroud)
与
ApplicationController
Run Code Online (Sandbox Code Playgroud)
我注意到如果我执行:: API,则需要在渲染时添加json:,然后才可以渲染msg
从API继承时,请求/响应的背后是否更精简?
class Api::V1::TestController < ????
def index
msg = {status: "ok", message: "hello world"}
render json: msg
end
end
Run Code Online (Sandbox Code Playgroud) java ×3
scala ×3
file-io ×2
servlets ×2
activerecord ×1
akka ×1
javascript ×1
jetty ×1
redis ×1
ruby ×1
spring-mvc ×1
tomcat ×1