我正在尝试使用hibernate映射mysql映射。我在jsp页面中给出了一个映射到tweetAction
类的putMessage()
方法的动作。我的问题是映射适用于userAction
类的方法。但是当我添加tweetAction
课程时,它根本不起作用。
我只想让这个流进入putMessage()
这就是为什么我输入一个SysOut方法只是为了在控制台上显示它
这是我的struts.xml:
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="default" extends="hibernate-default">
<action name="login" method="isAuthentic" class="com.vaannila.web.UserAction">
<result name="success">/home.jsp</result>
<result name="failure">/failure.jsp</result>
</action>
<action name="addUser" method="add" class="com.vaannila.web.UserAction">
<result name="success" type="redirect">listUser</result>
</action>
<action name="listUser" method="list" class="com.vaannila.web.UserAction">
<result name="success">/Login.jsp</result>
</action>
<action name="searchUser" method="search" class="com.vaannila.web.UserAction">
<result name="success">/display.jsp</result>
</action>
<action name="message" method="putMessage" class="com.vaannila.web.TweetAction">
<result name="success" >/Login.jsp</result>
</action>
</package>
</struts>
这是我的TweetAction.java:
package com.vaannila.web;
import java.util.ArrayList;
import java.util.List;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.vaannila.dao.TweetDAO;
import com.vaannila.dao.TweetDAOImpl;
import com.vaannila.dao.UserDAO;
import com.vaannila.dao.UserDAOImpl;
import com.vaannila.domain.Tweet;
import com.vaannila.domain.User;
public class TweetAction extends ActionSupport implements ModelDriven<Tweet> {
private static final long serialVersionUID = -6659925652584240539L;
private Tweet tweet = new Tweet();
private User user = new User();
private List<Tweet> tweetList = new ArrayList<Tweet>();
private TweetDAO tweetDAO = new TweetDAOImpl();
private boolean isAuthentic = false;
public Tweet getModel() {
// TODO Auto-generated method stub
return null;
}
public String putMessage()
{
System.out.println("inside putMessage");
return SUCCESS;
}
public String tweet()
{
return SUCCESS;
}
}
这是我的hibernate.cfg.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost/twitter</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">root</property>
<property name="connection.pool_size">1</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="hbm2ddl.auto">update</property>
<mapping class="com.vaannila.domain.User" />
<mapping class="com.vaannila.domain.Tweet" />
</session-factory>
</hibernate-configuration>
这是我的样本Home.jsp
<html>
<body>
<h2>What's on your mind?</h2>
<s:form action="message">
<s:textarea name="message" rows="4" cols="75" Placeholder="Enter here..." />
<s:submit /> <!-- type="image" src="tweet.jpg" align="center" -->
</s:form>
</body>
</html>
struts.xml中:
<action name="login" method="isAuthentic" class="com.vaannila.web.UserAction">
<result name="success">/temp.jsp</result>
<result name="failure">/failure.jsp</result>
</action>
<action name="addUser" method="add" class="com.vaannila.web.UserAction">
<result name="success" type="redirect">listUser</result>
</action>
<action name="listUser" method="list" class="com.vaannila.web.UserAction">
<result name="success">/Login.jsp</result>
</action>
<action name="searchUser" method="search" class="com.vaannila.web.UserAction">
<result name="success">/display.jsp</result>
</action>
<action name="message" method="putMessage" class="com.vaannila.web.TweetAction">
<result name="success">/temp.jsp</result>
</action>
</package>
谁能告诉我我做错了什么?
答案 0 :(得分:0)
Java Struts call another action after executed action finsihed
检查上面
你应该尝试<result type="redirectAction">/listTweet</result>
别忘了将/
放在动作名称
答案 1 :(得分:0)
在TweetAction中的getModel()方法中。返回值为null,我认为这是错误的。因为ModelInterceptor无法将数据封装到null实体中。
修饰:
public Tweet getModel()
{
return tweet;
}