我有以下(缩短)struts2动作:
public class MyAction extends BaseAction implements CookiesAware {
public String execute() {
if (cookiesMap.containsKey("BLAH"))
blah=Integer.parseInt(cookiesMap.get("BLAH"));
return "success";
}
// For handling cookies
Map<String, String> cookiesMap;
@Override
public void setCookiesMap(Map<String, String> cookiesMap) {
this.cookiesMap = cookiesMap;
}
}
Run Code Online (Sandbox Code Playgroud)
当我执行'cookiesMap.containsKey'时,我得到一个空指针异常 - 在我看来,没有调用setCookiesMap.我已经实现了CookiesAware界面,所以我认为它应该被调用 - 我错过了什么吗?
谢谢
我在向Struts 2动作类发送数组参数时遇到问题.我正在使用struts 2.1.8.1.
这是一些示例代码:
public class MyAction extends ActionSupport {
private String[] types;
public String execute() {
return SUCCESS;
}
public String[] getTypes() {
return types;
}
public void setTypes(String[] types) {
this.types = types;
}
}
Run Code Online (Sandbox Code Playgroud)
问题是通过jquery ajax方法发送数组时:
$.ajax({
type: 'POST',
url: 'Myaction.action',
data: {
types: ["this", "is", "a", "test"]
}
});
Run Code Online (Sandbox Code Playgroud)
导致异常发生:
ognl.ParseException: Encountered " "]" "] "" at line 1, column 7.
如何使用jQuery将数组发送到我的Struts2动作类?我需要包含拦截器的某些内容吗?或者jQuery中有一个选项可以删除它吗?
我也遇到了jQuery UI Sortable控件的这个问题,但是我用正则表达式解决了这个问题,删除了"[]"字符.我想避免这种情况,因为这个解决方案困扰着我.我想我可以自己构建字符串,而不是使用对象表示法,但除非你能说服我,否则我想使用对象表示法.
我有个疑问.Struts2 Modeldriven接口如何工作.在我的应用程序中,我用于单个表单.我将setter和getter与表单名称相同.是否可以ModelDriven使用setter和getter 放置多个对象.如果我这样放置它会如何识别?
我有一个相当愚蠢的问题.Struts2属性标记不会转义单引号(').这种行为破坏了我的JavaScript代码.它确实使用html实体转义双引号("),但不是单引号(').是否有可能强制属性标记用适当的html实体替换单引号?
例如,字符串替换为html实体.Отредактированноесобытиескавычкой "
单个qoute相同:Отредактированноесобытиескавычкой '
有没有可能使用标准方法克服这种困难?我不想写一些自定义代码.
启动tomcat时记录
Apr 28, 2011 10:52:57 AM org.apache.catalina.core.AprLifecycleListener init
INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: D:\software\jdk1.5.0_06\bin;.;C:\WINDOWS\system32;C:\WINDOWS;D:/software/jdk1.5.0_06/bin/../jre/bin/client;D:/software/jdk1.5.0_06/bin/../jre/bin;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\Program Files\TortoiseSVN\bin.;D:\software\jdk1.5.0_06\bin;D:\software\Ant 1.7\bin;D:\software\Axis2-1.5.4\axis2-1.5.4-bin\axis2-1.5.4\bin;C:\Program Files\IDM Computer Solutions\UltraEdit\
Apr 28, 2011 10:52:58 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:StrutsHelloWorld' did not find a matching property.
Apr 28, 2011 10:52:58 AM org.apache.tomcat.util.digester.SetPropertiesRule begin
WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:StrutsHelloWorld1' did not find a matching property.
Apr 28, 2011 10:53:00 AM …Run Code Online (Sandbox Code Playgroud) 我可以使用此标记显示特定字段的错误:
<s:fielderror fieldName="myField" />
Run Code Online (Sandbox Code Playgroud)
但除了显示错误消息之外,我还想以红色突出显示该字段.为此,我需要知道字段是否生成错误,然后将错误类添加到此字段.
如何检查特定字段是否生成错误?
我需要使用Struts2一次上传"1000个文件"或"包含所有文件的zip文件".(通过1000个文件或一个zip文件,我的意思是我需要在系统上传所有文件,如果用户一次选择所有1000个文件或者压缩它们并上传为单个文件,那么我无需重要,所以我正在寻找更容易实现和更有效的那个)
我已经阅读了以下答案,但它们都不符合目的.
使用下面的代码,当我使用一个简单的List文件时; 它显示了列表的名称,但是当我使用List文件时它没有显示任何内容,我无法上传文件.
upload.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form action="upload" enctype="multipart/form-data" method="post">
<input name="files" type="file" multiple/>
<button type="submit"/>
</form>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
upload.java
@Action
public class upload implements Addresses {
private List <File> files = new ArrayList <File> ();
public String execute(){
return "success";
}
public upload() {
System.out.println("in upload 1");
for(int i=0;i<files.size();i++)
System.out.println(i + ")" + files.get(i));
System.out.println("in upload 2");
}
public List <File> getFiles() …Run Code Online (Sandbox Code Playgroud) 我在使用Spring和Hibernate开发基于Struts2的Web应用程序时偶然发现了一个问题.
当我刷新网站几次,例如2-4次时,Hibernate出现了一个关于太多连接的例外.我试图实现C3P0连接池,并遇到一些问题
该hibernate.cfg.xml的配置:
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/axelle</property>
<property name="hibernate.connection.username">axelle</property>
<property name="hibernate.connection.password">dbpassword</property>
<property name="hibernate.current_session_context_class">thread</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.max_size">20</property>
<property name="hibernate.c3p0.timeout">300</property>
<property name="hibernate.c3p0.max_statements">50</property>
<property name="hibernate.c3p0.idle_test_period">3000</property>
Run Code Online (Sandbox Code Playgroud)
applicationContext.xml中
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="classpath:jdbc.properties"/>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}"
p:connectionProperties="${jdbc.connectionProperties}"/>
<!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) -->
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory"> …Run Code Online (Sandbox Code Playgroud) 我没有收到来自服务器的JSON类型数据的响应.
我正在使用JSON插件.
jQuery( "#dialog-form" ).dialog({
autoOpen: false,
height: 500,
width: 750,
modal: true,
buttons :{
"Search" : function(){
jQuery.ajax({type : 'POST',
dataType : 'json',
url : '<s:url action="part" method="finder" />',
success : handledata})
}
}
});
var handledata = function(data)
{
alert(data);
}
Run Code Online (Sandbox Code Playgroud)
如果dataType = 'json'我没有得到任何回复,但如果我没有提及任何回复,dataType我将获得该页面的HTML格式.
public String list(){
JSONObject jo = new JSONObject();
try {
Iterator it = findList.iterator();
while(it.hasNext()){
SearchResult part = (SearchResult) it.next();
jo.put("col1",part.getcol1());
jo.put("col2",part.getcol2());
}
log.debug("--------->:"+jo.toString());
} catch (Exception e) {
log.error(e); …Run Code Online (Sandbox Code Playgroud) 我将实现类似于Facebook通知和本网站的内容(StackOverflow的通知,如果有人为我们的问题撰写评论/答案等,则通知我们).请注意,用户将使用我的应用程序作为网站而不是移动应用程序.
我遇到了以下获取结果的答案,但我需要推送结果而不是获取.
根据建议,我在我的实体类中创建了一个简单的方法并添加了@PostPersist但它没有工作,基于这个答案我添加了persistence.xml文件来定义监听器但是在session.save(user)之后aftersave方法不会被触发.
User.java
@Entity
public class User{
.....
@PostPersist
public void aftersave(){
System.err.println("*****this is post persist method****");
}
}
Run Code Online (Sandbox Code Playgroud)
persistence.xml中
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<property name="hibernate.ejb.event.pre-insert" value="my.hibernate.events.listeners.Listener" />
<property name="hibernate.ejb.event.pre-update" value="my.hibernate.events.listeners.Listener" />
<property name="hibernate.ejb.event.pre-delete" value="my.hibernate.events.listeners.Listener" />
<property name="hibernate.ejb.event.post-insert" value="my.hibernate.events.listeners.Listener" />
<property name="hibernate.ejb.event.post-update" value="my.hibernate.events.listeners.Listener" />
<property name="hibernate.ejb.event.post-delete" value="my.hibernate.events.listeners.Listener" />
Run Code Online (Sandbox Code Playgroud)
的pom.xml
<dependency>
<groupId>org.hibernate</groupId> …Run Code Online (Sandbox Code Playgroud)