日期:2014-05-19  浏览次数:20686 次

SSH集成的问题!!谁来帮看下是什么问题?找不到页面~~~
基于S2SH框架的测试!!spring是采用的setter注入!
struts2配置文件:<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="user" extends="struts-default">
<action name="user" class="com.actions.UserAction">
<result name="ok">/ok.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>  

action页面package com.actions;

import com.entities.Users;
import com.opensymphony.xwork2.ActionSupport;
import com.services.UserService;

@SuppressWarnings("serial")
public class UserAction extends ActionSupport{
Users user;
UserService service;
public Users getUser() {
return user;
}
public void setUser(Users user) {
this.user = user;
}
public UserService getService() {
return service;
}
public void setService(UserService service) {
this.service = service;
}
/**
* 新增
* @return
*/
public String addUserAction(){
try {
service.addUser(user);
return "ok";
} catch (Exception e) {
return "error";
}
}
}

JSP页面<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
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 'index.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>
  <form action="<%=path %>/user!addUserAction" method="post">
  <input type="text" name="user.firstname"/><br/>
  <input type="text" name="user.lastname"/><br/>
  <input type="text" name="user.age"/><br/>
  <input type="submit" value="注册"/><br/>
  </form>
  </body>
</html>


------解决方案--------------------
404提示吗?那你也得给个具体的错误啊
------解决方案--------------------
你的Action里的属性spring没有注入进来,托管Action让spring管理
加入jar包struts2-spring-plugin.jar 
Action在spring里配置,然后struts.xml里class写Action的bean id
------解决方案--------------------
先看你tomcat启动有没有报错,在看你点击项目的时候有没有报错,在看点击后有没有报错,最后我们才能确定是为什么