Struts与hibernate整合中遇到的问题
register.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ taglib uri="/struts-tags" prefix="s"%> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>My JSP 'register.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <s:form action="re.action" method="post"> <s:textfield name="id" label="ID"></s:textfield> <s:textfield name="username" label="用户名"></s:textfield> <s:password name="password" label="密码"></s:password> <s:submit value="注册 "></s:submit> </s:form> </body> </html>
ReAction.java
package org.action; import org.dao.UserDao; import org.model.Info; import com.opensymphony.xwork2.ActionSupport; public class ReAction extends ActionSupport{ private String id; private String username; private String password; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } @Override public String execute() throws Exception { // TODO Auto-generated method stub UserDao dao=new UserDao(); boolean save=dao.saveInfo(info()); if(save){ return SUCCESS; } else return ERROR; } public Info info(){ Info info=new Info(); info.setId(this.getId()); info.setUsername(this.getUsername()); info.setPassword(this.getPassword()); return info; } }
struts.xml
<?xml version="1.0" encoding="UTF-8"?> <!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="struts-default"> <action name="test" class="org.action.MyAction"> <result name="error">/test.jsp</result> </action> <action name="re" class="org.action.ReAction"> <result name="success">/login.jsp</result> <result name="error">/reError.jsp</result> <result name="input">/register.jsp</result> </action> <action name="lo" class="org.action.LoAction"> <result name="success" type="redirect">/test.jsp</result> <result name="error">/login.jsp</result> <result name="input">/login.jsp</result> </action> <action name="addMessageAction" class="org.action.AddMessageAction"> <result name="success">/test.jsp</result> <result name="error">/addError.jsp</result> </action> <action name="lookAll" class="org.action.lookAllMessageAction"> <result name="success">/show.jsp</result> </action> <action name="delete" class="org.action.DeleteMessageAction"> <result name="success">deteleSuccess.jsp</result> <result name="error">/deleteError.jsp</result> </action> <action name="lookSelf" class="org.action.LookSelfMessageAction"> <result name="success">/showSelfMessage.jsp</result> </action> <action name="updateMessageAction" class="org.action.updateMessageAction"> <result name="success">/test.jsp</result> </action> </package> </struts>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>/index.jsp</welcome-file> </welcome-file-list> <login-config> <auth-method>BASIC</auth-method> </login-config> </web-app>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
老实说那是学校老师的作业,要求就是做一个整合。
如果劝你放弃Struts+Hibernate,换用SpringMVC+MyBatis是不是会被砍死!
希望各位Java Web大神能帮帮忙!