SSH问题 搞了几天了没弄出
先上结果。输入http://localhost:8080/ProjectShop/
Struts Problem Report
Struts has detected an unhandled exception:
Messages: There is no Action mapped for namespace / and action name index.
--------------------------------------------
Stacktraces
There is no Action mapped for namespace / and action name index. - [unknown location]
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:189)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:61)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:475)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:198)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:291)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
java.lang.Thread.run(Thread.java:662)
--------------------------------------------
You are seeing this page because development mode is enabled. Development mode, or devMode, enables extra debugging behaviors and reports to assist developers. To disable this mode, set:
struts.devMode=false
in your WEB-INF/classes/struts.properties file.
WEB 配置 默认进入index.jsp
struts.xml 加载 struts-default.xml
<?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>
<!-- OGNL可以使用静态方法 -->
<constant name="struts.ognl.allowStaticMethodAccess" value="true"/>
<package name="myshop-default" abstract="true" extends="struts-default">
<global-results>
<!-- 程序主页面 -->
<result name="index" type="redirectAction" >index</result>
</global-results>
</package>
</struts>
[解决办法]
struts.properties
struts.action.extension=html
struts.serve.static.browserCache=false
struts.configuration.xml.reload=true
struts.objectFactory=spring
struts.devMode=true
struts.locale=zh_CN
struts.i18n.encoding=UTF-8
struts.ui.theme=simple
struts.multipart.maxSize=8388608
BaseAction:
package com.gyj.action;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.apache.struts2.interceptor.ApplicationAware;
import org.apache.struts2.interceptor.RequestAware;
import org.apache.struts2.interceptor.SessionAware;
import org.springframework.beans.factory.annotation.Autowired;
import com.gyj.dao.product.ProductCategoryDao;
import com.gyj.dao.product.ProductDao;
import com.gyj.model.order.OrderItem;
import com.gyj.model.user.Customer;
import com.gyj.model.user.Users;
import com.opensymphony.xwork2.ActionSupport;
/**
* 基本Action对象,其它Action的父类
* @author GYJ
*/
public class BaseAction extends ActionSupport implements RequestAware,
SessionAware, ApplicationAware {
private static final long serialVersionUID = 1L;
protected Integer id;
protected Integer[] ids;
protected int pageNo = 1;
protected int pageSize = 3;
public static final String LIST = "list";
public static final String EDIT = "edit";
public static final String ADD = "add";
public static final String SELECT = "select";
public static final String QUERY = "query";
public static final String LEFT = "left";
public static final String RIGHT = "right";
public static final String INDEX = "index";
public static final String MAIN = "main";
public static final String MANAGER = "manager";
public static final String TOP = "top";
public static final String REG = "reg";
public static final String USER_LOGIN = "userLogin";
public static final String CUSTOMER_LOGIN = "customerLogin";
public static final String LOGOUT = "logout";
// 获取用户id
// 获取用户对象
public Customer getLoginCustomer(){
if(session.get("customer") != null){
return (Customer) session.get("customer");
}
return null;
}
// 获取管理员id
// 获取管理员对象
public Users getLoginUser(){
if(session.get("admin") != null){
return (Users) session.get("admin");
}
return null;
}
// 从session中取出购物车
@SuppressWarnings("unchecked")
protected Set<OrderItem> getCart(){
Object obj = session.get("cart");
if(obj == null){
return new HashSet<OrderItem>();
}else{
return (Set<OrderItem>) obj;
}
}
// 注入Dao
@Autowired
protected ProductCategoryDao categoryDao;
@Autowired
protected ProductDao productDao;
// Map类型的request
protected Map<String, Object> request;
// Map类型的session
protected Map<String, Object> session;
// Map类型的application
protected Map<String, Object> application;
public void setRequest(Map<String, Object> request) {
// 获取Map类型的request赋值
this.request = request;
}
public void setApplication(Map<String, Object> application) {
// 获取Map类型的application赋值
this.application = application;
}
public void setSession(Map<String, Object> session) {
// 获取Map类型的session赋值
this.session = session;
}
// 处理方法
public String index() throws Exception {
return INDEX;
}
public String manager() throws Exception {
return MANAGER;
}
public String main() throws Exception {
return MAIN;
}
public String add() throws Exception {
return ADD;
}
public String select() throws Exception {
return SELECT;
}
//
public String execute() throws Exception {
return SUCCESS;
}
public String top() throws Exception {
return TOP;
}
public String left() throws Exception {
return LEFT;
}
public String right() throws Exception {
return RIGHT;
}
public String reg() throws Exception{
return REG;
}
public String query() throws Exception{
return QUERY;
}
// getter和settter方法
public Integer[] getIds() {
return ids;
}
public void setIds(Integer[] ids) {
this.ids = ids;
}
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
this.pageNo = pageNo;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
}
IndexAction
package com.gyj.action;
import java.util.List;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import com.gyj.model.product.ProductCategory;
import com.gyj.model.product.ProductInfo;
@Scope("prototype")
@Controller("indexAction")
public class IndexAction extends BaseAction {
private static final long serialVersionUID = 1L;
@Override
public String execute() throws Exception {
// 查询所有类别
String where = "where parent is null";
categories = categoryDao.findByPage(-1, -1, where, null).getList();
// 查询推荐的商品
product_commend = productDao.findCommend();
// 查询销量最高的商品
product_sellCount = productDao.findSellprice();
// 查询人气高的商品
product_clickcount = productDao.findClickcount();
return SUCCESS;
}
// 所有类别
private List<ProductCategory> categories;
// 推荐商品
private List<ProductInfo> product_commend;
// 销售最好的商品
private List<ProductInfo> product_sellCount;
// 人气最高的商品
private List<ProductInfo> product_clickcount;
public List<ProductCategory> getCategories() {
return categories;
}
public void setCategories(List<ProductCategory> categories) {
this.categories = categories;
}
public List<ProductInfo> getProduct_commend() {
return product_commend;
}
public void setProduct_commend(List<ProductInfo> productCommend) {
product_commend = productCommend;
}
public List<ProductInfo> getProduct_sellCount() {
return product_sellCount;
}
public void setProduct_sellCount(List<ProductInfo> productSellCount) {
product_sellCount = productSellCount;
}
public List<ProductInfo> getProduct_clickcount() {
return product_clickcount;
}
public void setProduct_clickcount(List<ProductInfo> productClickcount) {
product_clickcount = productClickcount;
}
}
帮满看看
[解决办法]
默认的index.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META HTTP-EQUIV="Refresh" CONTENT="0;URL=index.html">
</head>
<body>
<center>
<img src="<%=request.getContextPath()%>/css/images/load.gif"><br>
<p>页面加载中......</p>
</center>
</body>
</html>