For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub
- This topic has 7 replies, 3 voices, and was last updated 20 years, 9 months ago by
Gabriel Khoa Bui.
-
AuthorPosts
-
Gabriel Khoa BuiMemberI got an error while I was trying a tiny code. I am using MyEclipse 4.0, Eclipse 3.1, jre 1.5 under Win. Point me the reason why, please. Thanx!
————————************Error***********———————————
HTTP Status 404 – Servlet action is not available
——————————————————————————–
type Status report
message Servlet action is not available
description The requested resource (Servlet action is not available) is not available.
——————————————————————————–
Apache Tomcat/5.5.11
(struts-config.xml)
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE struts-config PUBLIC “-//Apache Software Foundation//DTD Struts Configuration 1.1//EN” “http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd”>
<struts-config>
<data-sources >
<data-source key=”org.apache.struts.action.DATA_SOURCE”>
<set-property property=”minCount” value=”1″ />
<set-property property=”password” value=”” />
<set-property property=”maxCount” value=”5″ />
<set-property property=”user” value=”sa” />
<set-property property=”driverClass” value=”com.microsoft.jdbc.sqlserver.SQLServerDriver” />
<set-property property=”description” value=”” />
<set-property property=”url” value=”/databaseConnection.jsp” />
<set-property property=”autoCommit” value=”false” />
<set-property property=”readOnly” value=”false” />
<set-property property=”loginTimeout” value=”30″ />
</data-source></data-sources>
<form-beans >
<form-bean name=”userLoginForm” type=”com.phuxuanuni.struts.form.UserLoginForm” />
</form-beans>
<global-exceptions />
<global-forwards ></global-forwards>
<action-mappings >
<action
attribute=”userLoginForm”
input=”/userLogin.jsp”
name=”userLoginForm”
path=”/userLogin”
scope=”request”
type=”com.phuxuanuni.struts.action.UserLoginAction”>
<forward name=”success” path=”/userLoginSuccess.jsp” />
<forward name=”failure” path=”/userLogin.jsp” />
</action></action-mappings>
<message-resources parameter=”com.phuxuanuni.struts.ApplicationResources” />
<plug-in className=”com.microsoft.jdbc.sqlserver.SQLServerDriver” />
</struts-config>———————————–*****UserLoginAction ******————————–
//Created by MyEclipse Struts
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.0.0/xslt/JavaClass.xslpackage com.phuxuanuni.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;import com.phuxuanuni.struts.form.UserLoginForm;
import com.phuxuanuni.struts.bean.DatabaseConnection;/**
*
* XDoclet definition:
* @struts.action path=”/userLogin” name=”userLoginForm” input=”/userLogin.jsp” scope=”request” validate=”true”
* @struts.action-forward name=”success” path=”userLoginSuccess.jsp”
* @struts.action-forward name=”failure” path=”userLogin.jsp”
*/
public class UserLoginAction extends Action {// ——————————————————— Instance Variables
// ——————————————————— Methods
private Connection conn = null;
private ResultSet rs = null;
private PreparedStatement pre = null;/**
* Method execute
* @param mapping
* @param form
* @param request
* @param response
* @return ActionForward
*/
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception {
//instance a variety named userLoginForm from UserLoginForm class
UserLoginForm userLoginForm = (UserLoginForm) form;
//instance a variety named dataConn from DatabaseConnection class
DatabaseConnection dataConn = new DatabaseConnection();
//return value named userName
String userName = (String)userLoginForm.getUserName();
//return value named password
String password = (String)userLoginForm.getPassword();
try
{
//open a connection
conn = dataConn.getConnection();
//open a select SQL statement
String selectStatement = “SELECT * FROM LOGIN WHERE (userName ='”;
selectStatement += userName + “‘, password = ‘”;
selectStatement += password + “‘)”;
//execute the statement
pre = conn.prepareStatement(selectStatement);
//return resultset
rs = pre.executeQuery();
//if resultset is of values
if(rs.next())
{
request.setAttribute(“userName”, userLoginForm.getUserName());
return mapping.findForward(“success”);
}
//no more value of resultset
else
{
return mapping.findForward(“failure”);
}
}
finally
{
if(conn!=null) conn.close();
}
}
}——————————————-***UserLoginForm *****————————–
//Created by MyEclipse Struts
// XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.0.0/xslt/JavaClass.xslpackage com.phuxuanuni.struts.form;
import org.apache.struts.action.ActionForm;
/**
*
* XDoclet definition:
* @struts.form name=”userLoginForm”
*/
public class UserLoginForm extends ActionForm {// ——————————————————— Instance Variables
/** password property */
private String password;/** userName property */
private String userName;// ——————————————————— Methods
/**
* Returns the password.
* @return String
*/
public String getPassword() {
return password;
}/**
* Set the password.
* @param password The password to set
*/
public void setPassword(String password) {
this.password = password;
}/**
* Returns the userName.
* @return String
*/
public String getUserName() {
return userName;
}/**
* Set the userName.
* @param userName The userName to set
*/
public void setUserName(String userName) {
this.userName = userName;
}}
————–*****DatabaseConnection****——————————
package com.phuxuanuni.struts.bean;
import java.sql.DriverManager;
import java.sql.Connection;public class DatabaseConnection {
public DatabaseConnection() {
super();
// TODO Auto-generated constructor stub
}public Connection getConnection() throws Exception
{
// User Name for logging in MS SQL Server 7.0
String sqlUserName = “sa”;
//Password for logging in MS SQL Server 7.0
String sqlPasssword = “”;
//The name of database
String sqlDatabaseName = “ProjectServlet”;
//Instance a string which contains Microsoft MSSQL JDBC Driver URL
String connectionDriverManager;connectionDriverManager = “jdbc:microsoft:sqlserver://MANG:1433;User=”+sqlUserName+”;Password=”+sqlPasssword+”;Databasename=”+sqlDatabaseName;
Class.forName(“com.microsoft.jdbc.sqlserver.SQLServerDriver”);
return DriverManager.getConnection(connectionDriverManager);}
}
November 1, 2005 at 9:08 pm #240623
Riyad KallaMemberplease post your web.xml file, I think you forgot to add the ActionSerlvet mapping. MyEclipse will do this for you automatically when you add Struts capabilities, so either you are working with an existing project or maybe the web.xml file got changed in another way.
November 2, 2005 at 12:57 am #240640
Gabriel Khoa BuiMemberThanx a lot! I was following all steps which of the eBook ‘Struts CookBook’ and twas alrite! In fact, Im working with an existing project. When I changed the source of ‘UserLoginAction.java’, I got above error. I wanted to get the values of ResultSet, therefore, I could find the correct values from database. Could you me detail ?! Thanx! This is my ‘web.xml’:
<?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” version=”2.4″ xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd”>
<servlet>
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>3</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>November 2, 2005 at 8:44 am #240650
Riyad KallaMemberEverything looks fine, what does the JSP page look like that you are using to access this action?
(please use the CODE button below to wrap your code blocks, it will maintain formatting)
November 3, 2005 at 1:00 am #240708
Gabriel Khoa BuiMemberPerhaps I didn’t lay my beans in the same package? Here is the jsp file which I trying to acccess login action:
<%@ page language=”java” contentType=”text/html; charset=UTF-8″ errorPage=”/errorPage.jsp”%>
<%@ taglib uri=”http://jakarta.apache.org/struts/tags-bean” prefix=”bean”%>
<%@ taglib uri=”http://jakarta.apache.org/struts/tags-html” prefix=”html”%>
<%@ include file=”headerHomePage.html”%><html>
<head>
<title>userLoginForm.jsp</title>
</head>
<body>
<center><h3>Login form</h3></center>
<table width=”50%” border=”0″ align=”center”>
<html:form action=”/userLogin”>
<tr>
<td><FONT color=”#333128″>User name</FONT></td>
<td><html:text property=”userName” size=”25″ maxlength=”20″/><html:errors property=”userName”/></td>
</tr>
<tr>
<td><FONT color=”#333128″>Password</FONT></td>
<td><html:password property=”password” size=”25″ maxlength=”20″/><html:errors property=”password”/></td>
</tr>
<tr>
<td align=”right”><html:submit property=”submit” value=”Submit”/></td>
<td align=”left”><html:reset property=”cancel” value=”Cancel”/></td>
</tr>
</html:form>
</table>
</body>
</html>——————————————————–
November 3, 2005 at 5:17 am #240715
rateotyMemberyou should use /userLogin.do as action in your form tag, cause you’re mapping actions to the pattern *.do in your web.xml
regards Jürgen
November 3, 2005 at 9:40 am #240731
Riyad KallaMemberAye, Jurgen nailed it. Your action property for your form tag is wrong.
November 5, 2005 at 3:00 am #240874
Gabriel Khoa BuiMemberHm! It still does not do its work! I lost much time for Struts project. May be I kick it far way!
Best regards Khoa
-
AuthorPosts
