我注意到有不同的bean范围,如:
@RequestScoped
@ViewScoped
@FlowScoped
@SessionScoped
@ApplicationScoped
Run Code Online (Sandbox Code Playgroud)
每个人的目的是什么?如何为我的bean选择合适的范围?
我可以在GAE上序列化我的servlet中的List,但我不能反序列化它.我究竟做错了什么?
这是我在GAE中的视频类,它是序列化的:
package legiontube;
import java.util.Date;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class Video {
@PrimaryKey
private String id;
@Persistent
private String titulo;
@Persistent
private String descricao;
@Persistent
private Date date;
public Video(){};
public Video(String id, String titulo, String descricao, Date date) {
//super();
this.id = id;
this.titulo = titulo;
this.descricao = descricao;
this.date = date;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id; …
Run Code Online (Sandbox Code Playgroud) 我有这个结构:
WebContent
resources
components
top.xhtml
company
about_us.xhtml
index.xhtml
Run Code Online (Sandbox Code Playgroud)
top.xhtml
是一个组件,即在使用index.xthml
与about_us.xhtml
太.
top.xhtml
<ul>
<li><a href="index.xhtml">Home</a></li>
<li><a href="company/about_us.xhtml">About us</a></li>
...
</ul>
Run Code Online (Sandbox Code Playgroud)
所以我的问题是,当当前页面是index.xhtml
组件正确生成URL时,但当当前页面时about_us.xhtml
,它会生成错误的URL.我不能使用相对路径,因为它也会生成错误的URL.我认为这是因为组件基于*.xhtml
页面的当前路径.
我能找到的唯一解决方案是:
<ul>
<li><a href="${pageContext.request.contextPath}/webname/index.xhtml">Home</a></li>
<li><a href="${pageContext.request.contextPath}/webname/about_us.xhtml">About us</a></li>
...
</ul>
Run Code Online (Sandbox Code Playgroud)
但我认为根本不是"优雅".有任何想法吗?
即使用户知道某些页面的URL,我也想阻止访问某些页面.例如,/localhost:8080/user/home.xhtml
(需要先登录)如果没有记录则重定向到/index.xhtml
.
在JSF中如何做到这一点?我在Google上读到需要过滤器,但我不知道该怎么做.
我正在使用亚马逊的EC2来托管一个用JSP构建的网站:
http://ec2-50-17-144-64.compute-1.amazonaws.com:8080/p2p
我买了这个域名:www.p2pbrasil.com
如何将www.p2pbrasil.com重定向到我在Amazon EC2中的网站?
当有人输入www.p2pbrasil.com时,它会重定向到 http://ec2-50-17-144-64.compute-1.amazonaws.com:8080/p2p?
我有这些表:
我的意图是:用户可以是a company
或a person
但是每个人都有一些共同点,作为用户名是email
和password
,所以我使用JPA工具从表中生成实体,结果如下:
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.AUTO)
private int id;
private String email;
private String password;
private int reputation;
//bi-directional one-to-one association to Company
@OneToOne(mappedBy="user", cascade={CascadeType.ALL})
private Company company;
//bi-directional many-to-one association to Location
@OneToMany(mappedBy="user")
private List<Location> locations;
//bi-directional one-to-one association to Person
@OneToOne(mappedBy="user")
private Person person;
//bi-directional many-to-one association to Product
@OneToMany(mappedBy="user")
private List<Product> products;
//bi-directional many-to-one association to UserType
@ManyToOne …
Run Code Online (Sandbox Code Playgroud) 我希望在用户登录系统后控制访问权限.
例如:
administrator : can add, delete and give rights to employee
employee : fill forms only
...
Run Code Online (Sandbox Code Playgroud)
因此,在知道用户具有哪些权限后,检查数据库,我想限制该用户可以看到和执行的操作.有一个简单的方法吗?
编辑
@WebFilter("/integra/user/*")
public class LoginFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
HttpServletRequest req = (HttpServletRequest) request;
Authorization authorization = (Authorization) req.getSession().getAttribute("authorization");
if (authorization != null && authorization.isLoggedIn()) {
// User is logged in, so just continue request.
chain.doFilter(request, response);
} else {
// User is not logged in, so redirect to …
Run Code Online (Sandbox Code Playgroud) 我正在尝试执行以下代码:
private void crop(HttpServletRequest request, HttpServletResponse response){
int x = 100;
int y = 100;
int w = 3264;
int h = 2448;
String path = "D:images\\upload_final\\030311175258.jpg";
BufferedImage image = ImageIO.read(new File(path));
BufferedImage out = image.getSubimage(x, y, w, h);
ImageIO.write(out, "jpg", new File(path));
}
Run Code Online (Sandbox Code Playgroud)
但一直给我同样的错误:
java.awt.image.RasterFormatException: (x + width) is outside of Raster
sun.awt.image.ByteInterleavedRaster.createWritableChild(ByteInterleavedRaster.java:1230)
java.awt.image.BufferedImage.getSubimage(BufferedImage.java:1156)
Run Code Online (Sandbox Code Playgroud)
我的错误在哪里?
我想存储birthdate
所以我选择date
了MySQL,当我在我的数据库中创建我的实体时,结果如下:
import java.util.Date;
// ..code
@NotNull(message="fill you birthdate")
@Temporal(TemporalType.DATE)
private Date birthdate;
Run Code Online (Sandbox Code Playgroud)
但是当我试图坚持它时,它给了我这个错误:
在回调事件上执行自动Bean验证时违反了Bean验证约束:'prePersist'.有关详细信息,请参阅嵌入式ConstraintViolations.
我在这做错了什么?我正在阅读有关谷歌定义时区的内容,我来自巴西,我应该怎么做?
编辑
package entity;
import java.io.Serializable;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import org.hibernate.validator.constraints.Email;
import java.util.Date;
import java.util.List;
/**
* The persistent class for the user database table.
*
*/
@Entity
public class User implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer id;
@Temporal(TemporalType.DATE)
private Date birthdate;
@NotNull(message="informe seu e-mail")
@Email(message="e-mail inválido")
private String email;
@NotNull(message="informe …
Run Code Online (Sandbox Code Playgroud) 我试图阻止一个线程,但我不能这样做:
public class Middleware {
public void read() {
try {
socket = new Socket("192.168.1.8", 2001);
// code ..
Scan scan = new Scan();
thread = new Thread(scan);
thread.start();
} catch (UnknownHostException ex) {
ex.printStackTrace();
} catch (IOException ex) {
ex.printStackTrace();
}
}
class Scan extends Thread {
public void run() {
while (true) {
try {
// my code goes here
} catch (IOException ex) {
thread.currentThread().interrupt();
}
}
}
}
public void stop() {
Thread.currentThread().interrupt();
}
// get …
Run Code Online (Sandbox Code Playgroud)