Struts与hibernate整合中遇到的问题

发布于 2021-11-24 15:49:12 字数 5786 浏览 741 评论 3

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>



老是出现404错误,然后没什么提示,还有默认的index.jsp也提示找不到页面!求各位大神解决!




如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

永不分离 2021-11-29 07:50:21

老实说那是学校老师的作业,要求就是做一个整合。

反话 2021-11-28 22:40:58

如果劝你放弃Struts+Hibernate,换用SpringMVC+MyBatis是不是会被砍死!

如日中天 2021-11-25 07:38:32

希望各位Java Web大神能帮帮忙!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文