Уважаемые ГУРУ есть код, но почему то при отладке в браузере выдаётся сообщение что ресурс не доступен исходники прилагаю!!!
Модератор: Используйте кнопку SRC для форматирования текста
web.xml:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>actions</param-name>
<param-value>actions</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
</web-app>
index.jsp:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<%@ taglib prefix="struts" uri="META-INF/struts-tags.tld" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Запрос</title>
</head>
<body>
<h1>Запрос</h1>
<struts:form action="LoginAction" method="post">
<struts:textfield label="UserName" name="username"/>
<struts:password label="Password" name="password"/>
<struts:submit label="Go!!!"/>
</struts:form>
</body>
</html>
struts.xml:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>actions</param-name>
<param-value>actions</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>struts</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>
index.jsp
</welcome-file>
</welcome-file-list>
</web-app>
LoginAction.java:
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
package actions;
import java.io.*;
import java.util.*;
import java.util.logging.*;
import javax.servlet.http.*;
import javax.servlet.*;
import com.opensymphony.xwork2.*;
import org.apache.struts2.ServletActionContext;
import execDB.QueryDB;
public class LoginAction extends ActionSupport
{
protected String username;
protected String password;
protected String actionName="";
public PrintStream out;
/** Creates a new instance of LoginAction */
public String LoginAction() throws Exception,IOException
{
Map<String,Object> session=(Map<String,Object>)(ActionContext.getContext().getSession());
String actionName=(String)ActionContext.getContext().getName();
QueryDB QueryMy= new QueryDB();
try
{
if (actionName.equals("loginAction"))
{
QueryMy.execute(username,password,out);
return "success";
}
else
{
return "notsuccess";
}
}
catch (Throwable ex)
{
this .addActionError(ex.getMessage());
return "notsuccess";
}
}
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;
}
}