HttpServletRequest有一个方法setAttribute(String, Object).
如何从中提取此属性ContainterRequest?
我没找到:getAttribute方法!
码
public class AuthenticationFilter implements Filter {
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpReq = (HttpServletRequest) servletRequest;
// .... ....
httpReq.setAttribute("businessId", businessId);
}
}
Run Code Online (Sandbox Code Playgroud)
在泽西过滤器:
private class Filter implements ResourceFilter, ContainerRequestFilter {
public ContainerRequest filter(ContainerRequest request) {
// ..extract the attribute from the httpReq
}
}
Run Code Online (Sandbox Code Playgroud) 我试图从另一个方法调用类的main方法,如从命令行运行类时传递参数.有没有办法做到这一点?
我是Struts2的初学者.请告诉我为什么要延长ActionSupport课程?(当一个人没有验证或国际化的要求时)
延伸ActionSupport课程是否还有其他好处?
我可以在许多网站上看到Struts Action类不是线程安全的.我无法理解为什么会这样.
我还读了一本书,上面写着"Struts动作类被缓存并重用于性能优化,代价是必须以线程安全的方式实现动作类"
如何缓存动作类和线程安全相关?.
在Java servlet中,有<context-param>.在桌面应用程序中,我们通常定义自己的配置文件.
我应该在哪里为Struts2应用程序添加配置参数?例如,我的应用程序需要为用户输入设置时间限制,或者保存和读取存储在某处的文件,或者用户输入错误密码的最长时间等.我希望这些内容可配置.
人们通常在Struts2应用程序中执行此操作的方式是什么?任何最佳做法?
我有一个使用JPA/Hibernate和Google Guice的应用程序.Guice在a中被引导ServletContextListener并且它自己设置了EntityManagerFactory.
该应用程序在Tomcat 7上运行良好,但是当我部署到JBoss AS7时,它失败了,因为JBoss决定在调用my之前自动设置JPA ServletContextListener.
如何让JBoss不自动初始化JPA而是等待我ServletContextListener这样做?
更新
根据詹姆斯提供的链接:
在应用程序部署期间,检测到JPA使用(例如persistence.xml或@ PersistenceContext/Unit注释)并将Hibernate依赖项注入应用程序部署.
https://docs.jboss.org/author/display/AS71/JPA+Reference+Guide#JPAReferenceGuide-Introduction
我需要弄清楚如何禁用这种"自动检测"功能.
更新#2
可以通过将以下属性添加到persistence.xml来禁用JPA的容器管理:
<property name="jboss.as.jpa.managed" value="false" />
Run Code Online (Sandbox Code Playgroud)
根据这个主题,截至2012年2月,此功能仅适用于每晚构建.
有没有办法使用 Hibernate 或 JPA 注释来覆盖子类中字段的可选性?举个例子:
这是一个定义了许多公共字段的基类。对于下面的示例,我仅显示我想要在几个子类中覆盖的单个字段。在 中@MappedSuperclass,此字段是必需的(不允许为空)。
@MappedSuperclass
public abstract class GenericLog {
protected String sessionId;
@Basic(optional = false)
@Column(name = FIELD__SESSION_ID__COLUMN, length = 50)
public String getSessionId() {
return sessionId;
}
public void setSessionId(String sessionId) {
this.sessionId = sessionId;
}
}
Run Code Online (Sandbox Code Playgroud)
这是一个子类。它具有与父类中定义的相同的 sessionId 字段,唯一的区别是该字段在此类中应允许为空。
@Entity
@Table(name = LogError.TABLE_NAME)
@Cache(usage = CacheConcurrencyStrategy.NONE)
public class LogError extends GenericLog {
@Basic(optional = true)
@Column(name = FIELD__SESSION_ID__COLUMN, length = 50)
@Override
public String getSessionId() {
return super.getSessionId(); …Run Code Online (Sandbox Code Playgroud) 在此先感谢您的时间.
如果它有一个保存的值,我需要预先选择一个单选按钮.我基本上需要比较valuestack中的2个字符串来确定这一点.
(我现在无法使用<s:radio,因为我需要根据表单中的其他输入元素附加一些业务规则).
我试着像下面那样在<s:set里面做了保存的id的值,s:iterate然后像下面那样比较它们,但显然我没有把它弄好.
<s:set var="savedId" value="%{flag.problemId}"/>
<s:iterator value="problemIdList">
<s:set var="currentId" value='<s:property value="id"/>' />
<s:if test="%{#currentId.equals(#savedId)}" >
<input checked="checked" type="radio" name="problemId" id="problemId" value='<s:property value="id"/>'/> <s:property value="description"/> <br/>
</s:if>
<s:else>
<input type="radio" name="problemId" id="problemId" value='<s:property value="id"/>'/> <s:property value="description"/> <br/>
</s:else>
</s:iterator>
Run Code Online (Sandbox Code Playgroud)
基本上我需要比较两个字符串,我的代码如下.我知道我无法与下面的equals()进行比较 - 任何想法?
谢谢你!
<s:set var="savedId" value="%{flag.problemId}"/> <s:iterator value="problemIdList">
<s:if test=' <s:property value="id"/>.equals(<s:property value="savedId"/>) '>
<input checked="checked" type="radio" name="problemId" id="problemId" value='<s:property value="id"/>'/> <s:property value="description"/> <br/>
</s:if>
<s:else>
<input type="radio" type="radio" name="problemId" id="problemId" value='<s:property value="id"/>'/> …Run Code Online (Sandbox Code Playgroud) 我想创建一个包含文本框的表单,如下所示.我正在使用Struts2.
User Name
|Text Box for user name|
mail id
|Text box for mail id|
<s:textarea name="username" id="username" label="User Name"/>
Run Code Online (Sandbox Code Playgroud)
这显示:
User name |Text Box for user name|
Run Code Online (Sandbox Code Playgroud)
但我想要上面的格式.当我使用验证框架标签以斜体显示时,我想要正常文本.
我在Action类的Session对象中设置了一个ArrayList,如图所示
public class HelloWorld implements SessionAware
{
private Map session;
public HelloWorld() {
}
public String execute() {
List list = new ArrayList();
list.add("One");
list.add("One2");
list.add("One3");
list.add("One4");
list.add("One5");
list.add("One6");
list.add("One7");
session.put("MyList", list);
System.out.println("Hi inside ");
return "SUCCESS";
}
public void setSession(Map session) {
this.session = (Map) session;
}
public Map getSession() {
return (Map) session;
}
}
Run Code Online (Sandbox Code Playgroud)
请告诉我如何在JSP页面中访问此Session对象"MyList"我已经尝试过这种方式
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello World</title>
</head>
<body>
<%
Map session = ContextAction.getContext().getSession();
%>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
但我不知道使用ContextAction是否更好?请告诉我如何在JSP中访问此会话"MyList"
我已经看到这种模式现在在几个不同的地方使用,但我不确定它到底是什么或为什么需要它.鉴于我已经在优质项目中看到它,我确信它很有用,但我想理解它,而不是盲目地遵循它.我在Servlet过滤器和Struts2拦截器中特别看到了这种模式(在概念上与过滤器非常相似).
以下是Google Guice(Servlet)3.0的示例:
Context previous = localContext.get();
try {
localContext.set(new Context((HttpServletRequest) servletRequest,
(HttpServletResponse) servletResponse));
//dispatch across the servlet pipeline, ensuring web.xml's filterchain is honored
filterPipeline.dispatch(servletRequest, servletResponse, filterChain);
} finally {
localContext.set(previous);
}
Run Code Online (Sandbox Code Playgroud)
恢复finally块中的值有什么需要或好处?
晚上好 ;
我有一个问题,我正在研究struts2 Web应用程序.我正在使用数据库动态创建PDF.我想在网页上显示它,但我不知道我是怎么做的,任何人都可以帮助我.
谢谢...
我有一个字符串,显示一个逗号分隔符的数字,如下所示:
DecimalFormat formatter = new DecimalFormat("#,###.000000");
String toDouble=formatter.format(amount);
Run Code Online (Sandbox Code Playgroud)
现在我想删除BO类中的逗号来进行算术运算.我用这种格式:
StrCash_price_deal = StrCash_price_deal.replace(",", "");
double d = Double.valueOf(StrCash_price_deal.trim()).doubleValue();
Run Code Online (Sandbox Code Playgroud)
但它将值更改为零!我的技术是struts2