问题描述
- ssh框架登录报404求大神解答!!!
-
我的源码:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >contextConfigLocation
/WEB-INF/applicationContext.xmlSpring 配置文件位置
org.springframework.web.context.ContextLoaderListener
struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
struts2
/*login.jsp
applicationContext.xml配置
<?xml version="1.0" encoding="UTF-8"?>
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!-- 数据源 --><!-- session factory -->
<!-- session factory -->
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">org.hibernate.dialect.SQLServerDialect
truecom/entity/User.hbm.xml
<!-- 把DAO注入给Session工厂 -->
<!-- 把Service注入给DAO -->
<!-- 把Action注入给Service property name对应的是action里面的属性svc-->
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">/success.jsp
/login.jspUser.java
package com.entity;import java.io.Serializable;
public class User implements Serializable {
private Integer id;
private String username;
private String password;
public User(){}
public User(String username,String password){
this.username=username;
this.password=password;
}public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getUsername() { return username; } public void setUsername(String username) { this.username = username; } /** * @return the password */ public String getPassword() { return password; } /** * @param password the password to set */ public void setPassword(String password) { this.password = password; }
}
User.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">UserDao.java
package com.dao;import java.util.List;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.entity.User;
public class UserDao extends HibernateDaoSupport {
public void save(User user) { this.getHibernateTemplate().save(user); } public void update(User user) { this.getHibernateTemplate().update(user); } public void delete(User user) { this.getHibernateTemplate().delete(user); } public User getByPk(int pk) { List list = this.getHibernateTemplate().find("from User where id=" + pk); if (list.isEmpty()) { return null; } return (User) list.get(0); } public User getByUserName(String username) { List list = this.getHibernateTemplate().find("from User where username" + username+""); if (list.size()==0) { return null; } return (User) list.get(0); }
}
LoginService.java
package com.service;import com.dao.UserDao;
import com.entity.User;public class LoginService {
private UserDao userDao; public String login(String username, String password) { User user = userDao.getByUserName(username); if (null != user) { if (password.equals(user.getPassword())) { return "success"; } else { return "密码错误"; } } else { return "用户不存在"; } } public UserDao getUserDao() { return userDao; } public void setUserDao(UserDao userDao) { this.userDao = userDao; }
}
LoginAction.java
package com.action;import com.opensymphony.xwork2.ActionSupport;
import com.service.LoginService;public class LoginAction extends ActionSupport {
private String username; private String password; private LoginService svc; 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; } public LoginService getSvc() { return svc; } public void setSvc(LoginService svc) { this.svc = svc; } public String execute() { if (null == username || username.equals("")) { return ""; } String info = svc.login(username, password); if (info.equals("success")) { return "success"; } System.out.println(info); return "error"; }
}
login.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">
Insert title here
用户:
密码:
success.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html>登录成功页面
登录成功!
解决方案
要么把你的代码截图贴出来,要么贴出具体的错误信息。这样才能定位问题
解决方案二:
这个是报错的,我觉得网址哪里有问题,不是login.action,大神求指教。
解决方案三:
localhost:8080能访问吗??