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

天杀的404 登陆后上传出现404 不登陆上传成功 不知道为神马求指教
login.jsp页面

  <body>
  <form action="login" method="post">
  username:<input type="text" name="username"><br/>
  password:<input type="password" name="password"><br/>
  <input type="submit" value="submit">
  </body>


struts.xml页面

<package name="zhou" extends="struts-default">
<action name="login" class="ac.LoginAction">
<result name="success">/upload.jsp</result>
<result name="input">/index.jsp</result>





</action>
<action name="upload" class="ac.FileUploadAction">
<param name="savePath">/upload</param>
<result name="success">/show.jsp</result>
<result name="input">/upload.jsp</result>

</action>



</package>



login.action页面



package ac;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Map;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport {
private String username;
private String password;
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 String execute() throws Exception {
ActionContext actionContext = ActionContext.getContext();
Map session = actionContext.getSession();

String url = "jdbc:mysql://localhost:3306/";
String dbName = "zt";
String driverName = "com.mysql.jdbc.Driver";
String userName = "root";
String passWord = "123";

Connection con = null;
Statement stmt = null;
ResultSet rs = null;
try {
Class.forName(driverName).newInstance();
con = DriverManager.getConnection(url + dbName, userName, passWord);
stmt = con.createStatement();

} catch (Exception e) {
System.out.println(e.getMessage());
}
stmt = con.createStatement();
String sql = "select * from user where username='" + this.username
+ "'and password='" + this.password + "'";
rs = stmt.executeQuery(sql);

if (!rs.next()) {

return INPUT;
} else {
session.put("USER", this.username);
return SUCCESS;

}








}

}




upload.jsp




  <body>
  <s:form action="upload" method="post" enctype="multipart/form-data">
  <s:file name="imgfile" label="选择图片"></s:file>
  <s:text name="title"></s:text>
  <s:submit value="submit"/>
   
   
   
  </s:form>
  </body>



FileUploadAction页面



package ac;

import com.opensymphony.xwork2.ActionSupport;
import java.io.File;
import java.io.FileInputStream;