break行标签在firefox中不起作用,也不在chrome中.当我看到我的页面的来源时,我得到:
<p>Zugang zu Testaccount:</br></br>peter petrelli </br></br>sein Standardpwd.</br></br>peter.heroes.com</p>
Run Code Online (Sandbox Code Playgroud)
但是,当我查看选定的来源时,我得到:
<p>Zugang zu Testaccount: peter petrelli sein Standardpwd. peter.heroes.com</p>
Run Code Online (Sandbox Code Playgroud)
似乎firefox正在过滤断线标签.
它适用于IE7.
但是,我想尽可能用GZIP压缩我的回复.我尝试使用可在headfirst站点免费下载的压缩过滤器代码.它适用于HTML,图像,CSS和JavaScript.
我接下来发布过滤器.它检查GZIP是否为可接受的编码,并将gzip添加为Content-Encoding.看到:wrappedResp.setHeader("Content-Encoding", "gzip");
public class CompressionFilter implements Filter {
private ServletContext ctx;
private FilterConfig cfg;
/**
* The init method saves the config object and a quick reference to the
* servlet context object (for logging purposes).
*/
public void init(FilterConfig cfg)
throws ServletException {
this.cfg = cfg;
ctx = cfg.getServletContext();
//ctx.log(cfg.getFilterName() + " initialized.");
}
/**
* The heart of this filter wraps the response object with a Decorator
* that wraps the output stream with …Run Code Online (Sandbox Code Playgroud) 我在使用Gzip压缩和JQuery时遇到问题.它似乎可能是由我在Struts Actions中发送JSON响应的方式引起的.我使用下一个代码来发送我的JSON对象.
public ActionForward get(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
JSONObject json = // Do some logic here
RequestUtils.populateWithJSON(response, json);
return null;
}
public static void populateWithJSON(HttpServletResponse response,JSONObject json) {
if(json!=null) {
response.setContentType("text/x-json;charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
try {
response.getWriter().write(json.toString());
} catch (IOException e) {
throw new ApplicationException("IOException in populateWithJSON", e);
}
}
}
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法在Java Web应用程序中发送JSON?
如何在Java中将时间值转换为YYYY-MM-DD格式?
long lastmodified = file.lastModified();
String lasmod = /*TODO: Transform it to this format YYYY-MM-DD*/
Run Code Online (Sandbox Code Playgroud) 我想每隔几秒更改一个标题css背景图像,所以它看起来像幻灯片.
例如,前2秒是:
body#home h1#siteH1 { background:url(../images/header1.jpg) no-repeat;}
Run Code Online (Sandbox Code Playgroud)
接下来2秒钟:
body#home h1#siteH1 { background:url(../images/header2.jpg) no-repeat;}
Run Code Online (Sandbox Code Playgroud)
接下来2秒钟:
body#home h1#siteH1 { background:url(../images/header3.jpg) no-repeat;}
Run Code Online (Sandbox Code Playgroud)
然后再循环到header1.
如果有人知道如何以褪色效果进行过渡,那么它将是完美的.
我想在Tomcat容器中部署三个Grails Web应用程序.我使用的是Grails 1.3.7和Tomcat 7.0.23.我想将所有公共jar放在tomcat/shared/lib目录中.为什么?我想拥有较小的war文件并减少PermGen所需的内存量.
我配置conf/catalina.properites中的下一行
shared.loader=${catalina.base}/shared/lib,${catalina.base}/shared/lib/*.jar
Run Code Online (Sandbox Code Playgroud)
对于所有三个应用程序,我执行
grails war
Run Code Online (Sandbox Code Playgroud)
我将WEB-INF/lib下的所有*.jars复制到$ CATALINA_HOME/shared/lib中
后来我为每个应用程序生成没有jar的war文件
grails war --nojars
Run Code Online (Sandbox Code Playgroud)
我将所有三场战争都放在tomcat/webapps目录中.conf/DataSource.groovy中的生产dataSource 对于每个应用程序看起来如下.
应用A)
production {
dataSource {
dbCreate = "update"
username = "userA"
password="password"
url = "jdbc:mysql://localhost:3306/applicationA"
driverClassName = "org.gjt.mm.mysql.Driver"
}
}
Run Code Online (Sandbox Code Playgroud)
应用程序B)
production {
dataSource {
dbCreate = "update"
username = "userB"
password="password"
url = "jdbc:mysql://localhost:3306/applicationB"
driverClassName = "org.gjt.mm.mysql.Driver"
}
}
Run Code Online (Sandbox Code Playgroud)
应用C)
production {
dataSource {
dbCreate = "update"
username = "userC"
password="password"
url = "jdbc:mysql://localhost:3306/applicationC"
driverClassName = …Run Code Online (Sandbox Code Playgroud) 为了生成下一个SQL代码:
create table users (
user_name varchar(15) not null primary key,
user_pass varchar(15) not null);
create table user_roles(
username varchar(15) not null,
role_name varchar(15) not null,
primary key(usernmae, rolename)
);
Run Code Online (Sandbox Code Playgroud)
您可以使用以下代码:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="databaselayer.users.UserDB" table="users">
<id name="username" type="string" column="user_name">
<meta attribute="scope-set">public</meta>
</id>
<property name="password" type="string" column="user_pass" not-null="true"/>
<set name="roles" cascade="save-update" inverse="true">
<key column="user_name"/>
<one-to-many class="databaselayer.users.RoleDB"/>
</set>
</class>
<class name="databaselayer.users.RoleDB" table="user_roles">
<composite-id>
<key-many-to-one name="username" class="databaselayer.users.UserDB" column="user_name"/>
<key-property name="role" type="string" column="role_name"/>
</composite-id> …Run Code Online (Sandbox Code Playgroud) 我上传了一个带有struts表单的文件.我将图像作为byte [],我想缩放它.
FormFile file = (FormFile) dynaform.get("file");
byte[] fileData = file.getFileData();
fileData = scale(fileData,200,200);
public byte[] scale(byte[] fileData, int width, int height) {
// TODO
}
Run Code Online (Sandbox Code Playgroud)
任何人都知道一个简单的功能吗?
public byte[] scale(byte[] fileData, int width, int height) {
ByteArrayInputStream in = new ByteArrayInputStream(fileData);
try {
BufferedImage img = ImageIO.read(in);
if(height == 0) {
height = (width * img.getHeight())/ img.getWidth();
}
if(width == 0) {
width = (height * img.getWidth())/ img.getHeight();
}
Image scaledImage = img.getScaledInstance(width, height, Image.SCALE_SMOOTH);
BufferedImage imageBuff = new BufferedImage(width, …Run Code Online (Sandbox Code Playgroud) 我有一个域类,它扩展了一个抽象类,它注入了spring安全核心插件服务.
class Extra extends WithOwner {
String name
}
abstract class WithOwner {
transient springSecurityService
User user
def getCurrentUser() {
return springSecurityService.currentUser
}
def beforeValidate() {
if(!user) {
user = getCurrentUser()
}
}
Boolean isLoggedUserTheOwner(){
return (user?.id == getCurrentUser()?.id)
}
}
Run Code Online (Sandbox Code Playgroud)
我想实现一个控制器测试.
@TestFor(ExtraController)
@Mock([Extra, User, UserRole, Role])
class ExtraControllerTests {
void testEdit() {
def utils = new TestUtils()
def user1 = utils.saveUser1()
populateValidParams(params)
def extra = new Extra(params)
extra.user = user1
assert extra.save() != null
params.id = extra.id …Run Code Online (Sandbox Code Playgroud) 我有一个版本2.3.1的grails应用程序和下一个配置 BuildConfig.groovy
dependencies {
...
..
.
test "org.spockframework:spock-grails-support:0.7-groovy-2.0"
}
plugins {
test(":spock:0.7") {
exclude "spock-grails-support"
}
Run Code Online (Sandbox Code Playgroud)
我有下一个域类:
class Draft {
def grailsApplication
String name
String subject
String content
static constraints = {
name unique: true, blank: false
subject blank: false
}
static mapping = {
content type: 'text'
}
}
Run Code Online (Sandbox Code Playgroud)
我发现这篇文章使用Grails 2.x和Spock 0.7测试域约束,并使用一种有趣的方法来测试域类约束.
我有一个spock测试:
import spock.lang.Specification
abstract class ConstraintUnitSpec extends Specification {
String getLongString(Integer length) {
'a' * length
}
String getEmail(Boolean valid) {
valid ? "dexter@miamipd.gov" …Run Code Online (Sandbox Code Playgroud)