【发布时间】:2019-06-13 19:13:30
【问题描述】:
我在 Spring 应用程序中有一个控制器,我想用它处理一个 HTML 表单来更改 CSS。所以我将表单的操作设置为“changeCSS”,控制器从那里接管。我的问题是:我如何真正获得我在表单中提交的值?我在网上找到的资源都太复杂了,要我创建我并不真正需要的模型对象。
我要查找的值称为 color1、color2 等,它们应该替换 String.format() 方法中的硬编码颜色值。
@RequestMapping(value = "changeCSS", method = RequestMethod.GET)
public String changeCss() {
BufferedWriter writer;
try {
String colorNewSettings3 = String.format(colorSettings.get("3"), "#000");
String colorNewSettings4 = String.format(colorSettings.get("4"), "#fff");
String path = context.getRealPath("/static/css/custom.css");
BufferedWriter out = new BufferedWriter(new FileWriter(path));
out.write(colorNewSettings3+colorNewSettings4);
out.close();
} catch (IOException e) {
e.printStackTrace(); //Use a Logger here
}
return "settings";
}
【问题讨论】:
标签: java spring forms servlets