HTTP Status 404 in SSH+MVC web application - ssh

Here is my configration:
Tomcat 6<br/>
jdk1.6<br/>
MyEclipse
Win 7
HTTP Status 404 -
type Status report
I have a Dynamic Web Project set up in MyEclipse titled "ch21" with following structure. The web application works well local.But when I upload it to website.Then I can't call any jsp file.Such as index.jsp ,regist.jsp.
The error message is following.
HTTP Status 404
message
description The requested resource () is not available.
Apache Tomcat/6.0.29
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
</web-app>
struts.xml
<constant name="struts.i18n.encoding" value="gb2312"></constant>
<package name="struts2" extends="struts-default">
<action name="regist" class="regAction">
<result name="success" >/login.jsp</result>
<result name="input">/regist.jsp</result>
<result name="error">/regist.jsp</result>
</action>
</package>
I added the following in web.xml.
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>register.jsp</welcome-file>
</welcome-file-list>
I call http://example.net/index.jsp .But It can't work.
The error message :HTTP Status 404 .

I search other questions and then just now I asked the hosting.He help me and updata a jar(he didn't tell me detail),and he solve the question.Thank you very much!

Related

Secured REST call on Websphere

I am trying to create a secured REST service on WebSphere 8.5.0.2. I want to secure using basic authentication. I modified my web.xml and tryed to read auto injected SecurityContext. I get an auto injected object but various operations are failing for e.g. securityContext.getAuthenticationScheme();
I have also mapped my role to all authentiacted realm's users.
I could not find anything in Wink's documentation too. Am i doing anything wrong ?
My web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>RESTModulation</display-name>
<!-- Wink SDK servlet configuration.
This servlet handles HTTP requests
of SDK web service on application server.-->
<servlet>
<description>
JAX-RS Tools Generated - Do not modify</description>
<servlet-name>EntryRestServlet</servlet-name>
<servlet-class>com.ibm.websphere.jaxrs.server.IBMRestServlet</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>com.demo.DemoResourceApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>EntryRestServlet</servlet-name>
<url-pattern>
/resources/*</url-pattern>
</servlet-mapping>
<security-constraint id="SecurityConstraint_1">
<web-resource-collection id="WebResourceCollection_1">
<web-resource-name>EntryRestServlet</web-resource-name>
<description>Protection area for Rest Servlet</description>
<url-pattern>/resources/</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint id="AuthConstraint_1">
<description>Role1 for this rest servlet</description>
<role-name>Role1</role-name>
</auth-constraint>
</security-constraint>
<security-role id="SecurityRole_1">
<description>This is Role1</description>
<role-name>Role1</role-name>
</security-role>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>defaultWIMFileBasedRealm</realm-name>
</login-config>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
==========================================================================
Service implementation
#Path("/MyTestService")
public class MyTestService{
#Context
SecurityContext securityContext;
#GET
#Path("/getUser1")
#Produces(MediaType.TEXT_PLAIN)
public Response doInquiry()throws Exception {
String jsonData= "{'user':'I am here '}";
String authnScheme = securityContext.getAuthenticationScheme();
System.out.println("authnScheme : " + authnScheme);
// retrieve the name of the Principal that invoked the resource
String username = securityContext.getUserPrincipal().getName();
System.out.println("username : " + username);
// check if the current user is in Role1
Boolean isUserInRole = securityContext.isUserInRole("Role1");
System.out.println("isUserInRole : " + isUserInRole);
return Response.status(Response.Status.OK).entity(jsonData).build();
}
}
I did not pass correct password from REST client. After providing correct credentials, it has started working.

Configuring mybatis to print out sql failed in a web project

I am using:spring 4.2.3+MyBatis 3.4,and want configure mybatis to print out sql. Configurations are below:
**web.xml**
<?xml version="1.0" encoding="UTF-8"?>
...
<!-- spring config -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<!-- Spring GWT integration -->
<servlet>
<servlet-name>springGwtRemoteServiceServlet</servlet-name>
<servlet-class>org.spring4gwt.server.SpringGwtRemoteServiceServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>springGwtRemoteServiceServlet</servlet-name>
<url-pattern>/idp_web/service/*</url-pattern>
</servlet-mapping>
<!-- log4j -->
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>WEB-INF/log4j.properties</param-value>
</context-param>
<context-param>
<param-name>log4jRefreshInterval</param-name>
<param-value>3000</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<!-- Spring Security related configuration -->
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
**log4j.properties**
# Global logging configuration
log4j.rootLogger=DEBUG,stdout
# Console output...
log4j.appender.stdout = org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target = System.out
log4j.appender.stdout.Threshold = ALL
log4j.appender.stdout.layout = org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern = %5p [%t] - %m%n
#spring
log4j.logger.org.springframework = DEBUG
log4j.logger.org.spring4gwt.server = DEBUG
# SqlMap logging configuration...
log4j.logger.com.vsi.idp.mapper = TRACE,stdout
#log4j.logger.org.apache=TRACE,stdout
#log4j.logger.org.mybatis=TRACE,stdout
#log4j.logger.com.ibatis=TRACE,stdout
log4j.logger.java.sql=TRACE,stdout
log4j.logger.java.sql.Connection=TRACE,stdout
log4j.logger.java.sql.Statement=TRACE,stdout
log4j.logger.java.sql.PreparedStatement=TRACE,stdout
log4j.logger.java.sql.ResultSet=TRACE,stdout
When crud,nothing got printed out
What mistakes do I make?How to fix it to ensure sql got printed out?
and I have read this:
http://www.mybatis.org/mybatis-3/logging.html.
Just wondering,in a web project,will mybatis share same log4j configuration with spring automatically?Or should I add some configuration entries in applicationContext.xml to ensure sharing?
After add this to ApplicationContext.xml,sql got printed out
<!-- SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="typeAliasesPackage" value="com.domain.model" />
<!--**this line is key point**-->
<property name="configLocation" value="WEB-INF/mybatis-config.xml"/>
</bean>
//mybatis-config.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="logImpl" value="LOG4J"/>
</settings>
</configuration>

404 on weblogic hello world application

I'm trying to run a simple hello world web application to make sure I've got the structure of everything right.
Here's what I've got:
ear_test.ear
ear_test.ear/META-INF
ear_test.ear/META-INF/application.xml
ear_test.ear/META-INF/MANIFEST.MF
ear_test.ear/META-INF/weblogic-application.xml
ear_test.ear/test_web_project_1.war
ear_test.ear/test_web_project_1.war/META-INF
ear_test.ear/test_web_project_1.war/META-INF/MANIFEST.MF
ear_test.ear/test_web_project_1.war/WEB-INF/classes
ear_test.ear/test_web_project_1.war/WEB-INF/lib
ear_test.ear/test_web_project_1.war/WEB-INF/web.xml
ear_test.ear/test_web_project_1.war/helloWorld.jsp
application.xml
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_5.xsd" version="5">
<display-name>ear_test</display-name>
<module>
<web>
<web-uri>test_web_project_1.war</web-uri>
<context-root>/test_web_project_1</context-root>
</web>
</module>
</application>
weblogic-application.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<weblogic-application>
<session-descriptor>
<cookie-name>WLSSessionID</cookie-name>
<cookie-http-only>false</cookie-http-only>
<debug-enabled>false</debug-enabled>
<sharing-enabled>true</sharing-enabled>
</session-descriptor>
</weblogic-application>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>test_web_project_1</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>helloWorld.jsp</welcome-file>
</welcome-file-list>
</web-app>
I can deploy this to weblogic and it shows as active.
However when I try access the webapp, via:
http://myserver:7011/test_web_project_1
I get a 404 error.
Any suggestions for resolving this?
Check your URL again, make sure you are actually referencing the right URL for the server your application is deployed on.

Log4jdbc doesn't work in web project

Today, I integrate Log4jdbc 1.2 with Spring 3.1 Struts 2.1 Hibernate 4.1 in order to see the real SQL in console.
My project run normally,however, I don't get the real SQL.The amazing
thing is that I do get the SQL when I test with JUnit.
here is my log4j.properties
log4j.debug=true
log4j.logger.jdbc.audit=INFO,jdbc
log4j.additivity.jdbc.audit=true
log4j.logger.jdbc.resultset=INFO,jdbc
log4j.additivity.jdbc.resultset=true
log4j.logger.jdbc.sqlonly=DEBUG,sql
log4j.additivity.jdbc.sqlonly=true
log4j.logger.jdbc.sqltiming=DEBUG,sqltiming
log4j.additivity.jdbc.sqltiming=true
log4j.logger.jdbc.connection=FATAL,connection
log4j.additivity.jdbc.connection=true
log4j.appender.sql=org.apache.log4j.FileAppender
log4j.appender.sql.File=./logs/sql.log
log4j.appender.sql.Append=false
log4j.appender.sql.layout=org.apache.log4j.PatternLayout
log4j.appender.sql.layout.ConversionPattern=-----> %d{yyyy-MM-dd HH:mm:ss.SSS} %m%n%n
log4j.appender.sqltiming=org.apache.log4j.FileAppender
log4j.appender.sqltiming.File=./logs/sqltiming.log
log4j.appender.sqltiming.Append=false
log4j.appender.sqltiming.layout=org.apache.log4j.PatternLayout
log4j.appender.sqltiming.layout.ConversionPattern=-----> %d{yyyy-MM-dd HH:mm:ss.SSS} %m%n%n
log4j.appender.jdbc=org.apache.log4j.FileAppender
log4j.appender.jdbc.File=./logs/jdbc.log
log4j.appender.jdbc.Append=false
log4j.appender.jdbc.layout=org.apache.log4j.PatternLayout
log4j.appender.jdbc.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} %m%n
log4j.appender.connection=org.apache.log4j.FileAppender
log4j.appender.connection.File=./logs/connection.log
log4j.appender.connection.Append=false
log4j.appender.connection.layout=org.apache.log4j.PatternLayout
log4j.appender.connection.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss.SSS} %m%n
And my web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>Spring14HibernateStruts2</display-name>
<context-param>
<param-name>log4jConfigLocation</param-name>
<param-value>classpath:log4j.properties</param-value>
</context-param>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
</listener>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
</web-app>

Problems getting Tiles work with Struts2

I'm using struts 2.2.1 and tiles 2.2.2. I've done every step described here but I cannot get tiles work... I get the following error while deploying my war to glassfish 3.1:
[#|2011-10-04T08:43:28.117+0200|SEVERE|glassfish3.1|javax.enterprise.system.tools.admin.org.glassfish.deployment.admin|_ThreadID=74;_ThreadName=AutoDeployer;|Exception while invoking class com.sun.enterprise.web.WebApplication start method
java.lang.Exception: java.lang.IllegalStateException: ContainerBase.addChild: start: org.apache.catalina.LifecycleException: java.lang.IllegalArgumentException: java.lang.ClassNotFoundException: org.apache.struts2.tiles.StrutsTilesListener
at com.sun.enterprise.web.WebApplication.start(WebApplication.java:130)
In my WEB-INF/lib I've got commons-collections-3.1.jar, commons-fileupload-1.2.1.jar, struts2-core-2.2.1.jar, tiles-api-2.2.2.jar, tiles-core-2.2.2.jar, tiles-jsp-2.2.2.jar and xwork-core-2.2.1.jar.
This is my 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">
<struts>
<constant name="struts.devMode" value="true" />
<package name="basicstruts2" extends="struts-default">
<interceptors>
<interceptor-stack name="appDefault">
<interceptor-ref name="defaultStack">
<param name="exception.logEnabled">true</param>
<param name="exception.logLevel">ERROR</param>
</interceptor-ref>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="appDefault" />
<result-types>
<result-type name="tiles" class="org.apache.struts2.views.tiles.TilesResult" />
</result-types>
<global-results>
<result name="exception">/jsp/exceptions/exception.jsp</result>
<result name="webServiceException">/jsp/exceptions/webserviceexception.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="exception" />
<exception-mapping exception="java.io.IOException" result="exception" />
<exception-mapping exception="exceptions.WebServiceExceptionForStruts"
result="webServiceException" />
</global-exception-mappings>
<action name="tilesTest" class="test.action.TilesTest">
<result name="success" type="tiles">/welcome.tiles</result>
</action>
<action name="index">
<result>/jsp/index.jsp</result>
</action>
</package>
</struts>
After inserting the code into my struts.xml, I get this error in eclipse:
And this is my web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="2.4" 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">
<display-name>Consumer</display-name>
<welcome-file-list>
<welcome-file>/jsp/index.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class>
</listener>
<context-param>
<param-name>tilesDefinitions</param-name>
<param-value>/WEB-INF/tiles.xml</param-value>
</context-param>
</web-app>
Thank you very much!
You're missing the S2 tiles plugin. It's listed in the referenced article.
Your second issue with the XML is clearly stated in the IDE error; the order of elements given in the error message isn't the order you define the elements in your XML file.
ClassNotFoundException, looks like missing jar issue. Can you see the tiles plugin jar in war that is getting deployed on glassfish server.if not check check the war creation setting in you IDE. We faced this problem when it was not pushing jars from lib to the war.
ClassNotFoundException Always alerts you that some class/jar which is referenced is missing. Make sure you have all the basic jars required for tiles.
In my case, I have these jars (besides struts2 jars) in my struts2 application to test a demo tile project.
commons-beanutils-1.7.0.jar
commons-digester-2.0.jar
commons-logging-1.1.1.jar
commons-logging-api-1.1.jar
ognl-3.0.1.jar
slf4j-api-1.6.2.jar
slf4j-simple-1.6.2.jar
struts2-tiles-plugin-2.2.3.1.jar
tiles-api-2.2.2.jar
tiles-compat-2.2.2.jar
tiles-core-2.2.2.jar
tiles-jsp-2.2.2.jar
tiles-servlet-2.2.2.jar
tiles-template-2.2.2.jar
Best of luck.
Regards,
Amir Ali